def dump(self, language): d = dict([(k, v) for k, v in vars(self).items() if not k.startswith('_') and not k == 'geom']) locale = I18n.I18n() lang = locale.match_language(language) d['id'] = 's' + d['schema'] + 'id' + str(d['errorId']) d['annotationCoordinate'] = [ float(d.pop('latitude')), float(d.pop('longitude')) ] d['geomType'] = 'point' if d['osmType'] == 'node' else 'line' d['koinReward'] = d.pop('fix_koin_count') d['koinRewardWhenComplete'] = d.pop('vote_koin_count') d['question'] = locale.translate_question(lang, d['question'], d.pop('txt1'), d.pop('txt2'), d.pop('txt3'), d.pop('txt4'), d.pop('txt5')) d['title'] = locale.translate(lang, d['title']) input_type = MissionTypeLoader() d['inputType'] = copy.deepcopy( input_type.get_input_type( lang=lang, type_id=d['error_type'], input_type_name=d.pop('view_type'), re_description=d.pop('constraint_re_description'), re=d.pop('constraint_re'), lower_bound=d.pop('constraint_lower_bound'), upper_bound=d.pop('constraint_upper_bound'))) return d
def dump(self, language, achieved, achievementDate): d = dict([(k, v) for k, v in vars(self).items() if not k.startswith('_')]) locale = I18n.I18n() lang = locale.match_language(language) d['achievementDate'] = achievementDate.strftime( "%d/%m/%y") if achievementDate else None d['achievementTitle'] = locale.translate(lang, d.pop('title')) d['achieved'] = achieved d['achievementId'] = d.pop('id') d['achievementImageURI'] = d.pop('name') d['achievementDescription'] = locale.translate(lang, d.pop('description')) return d
def get_input_type(self, lang, type_id, input_type_name, re_description, re, lower_bound, upper_bound): try: locale = I18n.I18n() input_type = { 'constraints': { 'description': locale.translate(lang, re_description) or '', 're': re or '', 'lowerBound': lower_bound or '', 'upperBound': upper_bound or '' }, 'options': locale.translate_list( lang, copy.deepcopy(self.options.get(type_id, []))), 'values': self.values.get(type_id, []), 'name': locale.translate(lang, input_type_name) } except Exception as e: logger.error(traceback.format_exc()) return input_type
from .wakeup import wakeup from . import config from .loggers import setup_client from i18n import I18n, load as load_i18n from .matchmaking import Matchmaking client = commands.Bot(cmdargs.prefix, activity=discord.Game(',mahjong join')) client.should_stop = False @client.command() async def tiles(ctx: commands.Context, *, arg: str): await ctx.send(emojis.tiles(arg)) load_i18n() client.add_cog(I18n()) client.add_cog(Matchmaking(client)) @commands.is_owner() @client.command() async def stop(ctx: commands.Context): await emojis.add_ok(ctx) client.should_stop = True setup_client(client) client.loop.create_task(wakeup(client)) client.run(config.token)
loglevel = logging.DEBUG if DEBUG else logging.INFO logging.basicConfig(level=loglevel, format='[%(asctime)s] [%(levelname)s] %(message)s') log = logging.getLogger('totes') logging.getLogger('requests').setLevel(loglevel) db = sqlite3.connect("totes.sqlite3") cur = db.cursor() r = praw.Reddit(USER_AGENT, domain=DOMAIN) i18n = I18n() PATH_REGEX = re.compile(r'^/r/([^/]+)/comments/([a-z0-9]{6,8})(/[^/]+/([a-z0-9]{6,8}))?') def log_error(e): log.error("Unexpected {}:\n{}".format(e.__class__.__name__, traceback.format_exc())) def np(url): """ Transforms a reddit link into a no participation URL (which in some subreddits hides voting arrows, to help prevent administrator shadowbans. :param url: URL to transform :return: A no participation (NP) link