Skip to content

Commit

Permalink
Add missing plugin exeample endpoints & minor fixes to screenPath.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Grennith committed Jun 25, 2021
1 parent 9e20afe commit b8677e9
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 20 deletions.
5 changes: 4 additions & 1 deletion mapadroid/db/helper/SettingsPogoauthHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ async def get_unassigned(session: AsyncSession, instance_id: int, auth_type: Opt

@staticmethod
async def get_assigned_to_device(session: AsyncSession, instance_id: int,
device_id: int) -> List[SettingsPogoauth]:
device_id: int,
type_of_login: Optional[LoginType] = None) -> List[SettingsPogoauth]:
stmt = select(SettingsPogoauth).where(and_(SettingsPogoauth.instance_id == instance_id,
SettingsPogoauth.device_id == device_id))
if type_of_login:
stmt = stmt.where(SettingsPogoauth.login_type == type_of_login.value)
result = await session.execute(stmt)
return result.scalars().all()

Expand Down
3 changes: 3 additions & 0 deletions mapadroid/mapping_manager/MappingManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,9 @@ async def get_devicesetting_value_of_device(self, device_name: str, key: Mapping
return devicemapping_entry.pool_settings.enhanced_mode_quest_safe_items if devicemapping_entry.pool_settings and devicemapping_entry.pool_settings.enhanced_mode_quest_safe_items else devicemapping_entry.device_settings.enhanced_mode_quest_safe_items
elif key == MappingManagerDevicemappingKey.CLEAR_GAME_DATA:
return devicemapping_entry.device_settings.clear_game_data
# Extra keys to e.g. retrieve PTC accounts
elif key == MappingManagerDevicemappingKey.PTC_LOGIN:
return devicemapping_entry.ptc_logins
else:
# TODO: Get all the DB values...
pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ class MappingManagerDevicemappingKey(IntEnum):
GGL_LOGIN_MAIL = 38
LAST_QUESTCLEAR_TIME = 39
ENHANCED_MODE_QUEST_SAFE_ITEMS = 40
PTC_LOGIN = 41
30 changes: 11 additions & 19 deletions mapadroid/ocr/screenPath.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import numpy as np

from mapadroid.db.model import SettingsPogoauth
from mapadroid.ocr.screen_type import ScreenType
from mapadroid.mapping_manager import MappingManager
from mapadroid.mapping_manager.MappingManagerDevicemappingKey import MappingManagerDevicemappingKey
Expand Down Expand Up @@ -67,22 +68,24 @@ async def get_login_accounts(self) -> None:
await self.get_devicesettings_value(MappingManagerDevicemappingKey.LOGINTYPE, 'google')]
self._logger.info("Set logintype: {}", self._logintype)
if self._logintype == LoginType.ptc:
temp_accounts = await self.get_device_value('ptc_login', [])
temp_accounts: List[SettingsPogoauth] = await self.get_devicesettings_value(
MappingManagerDevicemappingKey.PTC_LOGIN, [])
if not temp_accounts:
self._logger.warning('No PTC Accounts are set - hope we are login and never logout!')
self._logger.warning('No PTC Accounts are set - hope we are logged in and never logout!')
self._accountcount = 0
return
for username, password in temp_accounts:
self._PTC_accounts.append(Login_PTC(username, password))
for auth in temp_accounts:
self._PTC_accounts.append(Login_PTC(auth.username, auth.password))
self._accountcount = len(self._PTC_accounts)
else:
temp_accounts = await self.get_devicesettings_value(MappingManagerDevicemappingKey.GGL_LOGIN_MAIL, None)
if not temp_accounts:
google_login_mail: Optional[str] = await self.get_devicesettings_value(
MappingManagerDevicemappingKey.GGL_LOGIN_MAIL, None)
if not google_login_mail:
# TODO: self._logger.warning('No GGL Accounts are set - using first @gmail.com Account')
return
temp_accounts = temp_accounts.replace(' ', '').split('|')
google_accounts = google_login_mail.replace(' ', '').split('|')

for account in temp_accounts:
for account in google_accounts:
self._GGL_accounts.append(Login_GGL(account))
self._accountcount = len(self._GGL_accounts)

Expand Down Expand Up @@ -569,17 +572,6 @@ async def get_devicesettings_value(self, key: MappingManagerDevicemappingKey, de
else:
return value

async def get_device_value(self, key: str, default_value: object = None) -> Optional[List]:
self._logger.debug2("Fetching devicemappings")
try:
devicemappings: Optional[dict] = await self._mapping_manager.get_devicemappings_of(self.origin)
except (EOFError, FileNotFoundError) as e:
self._logger.warning("Failed fetching devicemappings in worker with description: {}. Stopping worker", e)
return None
if devicemappings is None:
return default_value
return devicemappings.get(key, default_value)

def censor_account(self, emailaddress, is_ptc=False):
# PTC account
if is_ptc:
Expand Down
14 changes: 14 additions & 0 deletions plugins/madPluginExample/endoints/ExampleEndpoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from mapadroid.plugins.endpoints.AbstractPluginEndpoint import AbstractPluginEndpoint
import aiohttp_jinja2


class ExampleEndpoint(AbstractPluginEndpoint):
"""
"/example"
"""

# TODO: Auth
@aiohttp_jinja2.template('testfile.html')
async def get(self):
return {"header": "Test Plugin",
"title": "Test Plugin"}
14 changes: 14 additions & 0 deletions plugins/madPluginExample/endoints/PluginfaqEndpoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from mapadroid.plugins.endpoints.AbstractPluginEndpoint import AbstractPluginEndpoint
import aiohttp_jinja2


class PluginfaqEndpoint(AbstractPluginEndpoint):
"""
"/pluginfaq"
"""

# TODO: Auth
@aiohttp_jinja2.template('pluginfaq.html')
async def get(self):
return {"header": "Test Plugin",
"title": "Test Plugin - FAQ"}
10 changes: 10 additions & 0 deletions plugins/madPluginExample/endoints/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from aiohttp import web

from plugins.madPluginExample.endoints.ExampleEndpoint import ExampleEndpoint
from plugins.madPluginExample.endoints.PluginfaqEndpoint import PluginfaqEndpoint


def register_custom_plugin_endpoints(app: web.Application):
# Simply register any endpoints here. If you do not intend to add any views (which is discouraged) simply "pass"
app.router.add_view('/example', ExampleEndpoint, name='example')
app.router.add_view('/pluginfaq', PluginfaqEndpoint, name='pluginfaq')

0 comments on commit b8677e9

Please sign in to comment.