示例#1
0
 def acceptModal(reaction,user,modal):
     modal.content = localisation.getFormattedMessage('setprefix_changing',prefix=modal.prefix,lang=modal.locale)
     modal.actions = {}
     yield from modal.reset()
     yield from update_prefix(modal.message.server.id,modal.prefix,
         finish_modal(modal,localisation.getFormattedMessage('setprefix_success',prefix=modal.prefix,lang=modal.locale)),
         finish_modal(modal,localisation.getMessage('setprefix_error',lang=modal.locale))
     )
示例#2
0
 def run(self,client,command,msg,settings):
     locale = settings.get('locale')
     try:
         self.sql.delete_link(msg.author.id)
         self.content = localisation.getFormattedMessage('unlink_success',author=msg.author.id,lang=locale)
     except:
         traceback.print_exc()
         self.content = localisation.getFormattedMessage('unlink_error',author=msg.author.id,lang=locale)
示例#3
0
 def change_language(reaction,user,modal):
     locale = modal.flagMap.get(str(reaction.emoji))
     modal.embed = TextEmbed(text=localisation.getFormattedMessage('setlocale_change',locale=locale,lang=modal.locale))
     modal.actions = {}
     yield from modal.reset()
     yield from update_locale(modal.message.server.id,locale,
         finish_modal(modal,embed=localisation.getFormattedMessage('setlocale_success',locale=locale,lang=locale)),
         finish_modal(modal,embed=localisation.getMessage('setlocale_error',lang=modal.locale))
     )
示例#4
0
 def run(self,client,command,msg,settings):
     locale = settings.get('locale')
     try:
         status = yield from meta.getStatus()
         self.content = localisation.getFormattedMessage('servers_success',author=msg.author.id,lang=locale)
         self.embed = StatusEmbed(status['online'],status['message'])
         for s in status['services']:
             self.embed.add_service(name=s,value=status['services'][s])
     except:
         self.content = localisation.getFormattedMessage('servers_error',author=msg.author.id,lang=locale)
示例#5
0
def noPermission(client, msg,type,settings):
    locale = settings.get('locale')
    serverid = msg.server.id
    if type == 'error':
        m = localisation.getFormattedMessage('error',author=msg.author.id,lang=locale)
    elif type in settings['channels']:
        m = localisation.getFormattedMessage('wrong_channel',author=msg.author.id,type=type,channel=settings['channels'][type],lang=locale)
    elif type == 'setchannel' or type == 'resetchannels':
        m = localisation.getFormattedMessage('channel_administrator',author=msg.author.id,lang=locale)
    else:
        m = localisation.getFormattedMessage('nopermission',author=msg.author.id,lang=locale)
    mymsg = yield from client.send_message(msg.channel,m)
    yield from asyncio.sleep(5)
    yield from client.delete_message(msg)
    yield from client.delete_message(mymsg)
示例#6
0
 def run(self,client,command,msg,settings):
     locale = settings.get('locale')
     urls = command.split(" ")
     type = None
     if len(urls) < 2:
         backgrounds = []
     else:
         if urls[1].lower() in self.background_types:
             type = urls[1].lower()
             backgrounds = urls[2:]
         else:
             backgrounds = urls[1:]
     if type is not None:
         self.settings = {'backgrounds': {type:backgrounds}}
         self.content = localisation.getFormattedMessage('setbackground_success',author=msg.author.id,type=type,lang=locale)
     else:
         self.content = localisation.getFormattedMessage('setbackground_error',author=msg.author.id,types=arrays.message_string(self.background_types),lang=locale)
示例#7
0
 def run(self,client,command,msg,settings):
     locale = settings.get('locale')
     command_size = len('link ')
     if len(command) > command_size:
         user = yield from parse_fortnite_user(command[command_size:])
         name = user.get('name')
         platform = user.get('platform')
         if len(name.strip()) > 0:
             self.content = localisation.getFormattedMessage('link_success',author=msg.author.id,username=name,platform=platform,lang=locale)
             try:
                 self.sql.set_link(msg.author.id,name,platform)
             except:
                 traceback.print_exc()
                 self.content = localisation.getFormattedMessage('link_error',author=msg.author.id,lang=locale)
         else:
             self.content = localisation.getFormattedMessage('link_short',author=msg.author.id,lang=locale)
     else:
         self.content = localisation.getFormattedMessage('link_short',author=msg.author.id,lang=locale)
示例#8
0
 def run(self,client,command,msg,settings):
     locale = settings.get('locale')
     serverid = msg.server.id
     try:
         type = command.split(" ")[1].lower()
     except IndexError:
         type = None
     if type is None:
         self.settings = {'channels':{}}
         for channeltype in self.types:
             self.settings['channels'][channeltype] = None
         self.content = localisation.getFormattedMessage('resetchannels_all',author=msg.author.id,lang=locale)
     else:
         if type in self.types:
             self.settings['channels'] = {}
             self.settings['channels'][type] = None
             self.content = localisation.getFormattedMessage('resetchannels_success',author=msg.author.id,type=type,lang=locale)
         else:
             self.content = localisation.getFormattedMessage('resetchannels_error',author=msg.author.id,lang=locale)
示例#9
0
 def run(self,client,command,msg,settings):
     locale = settings.get('locale')
     news = meta.getNews(locale)
     if news['success']:
         self.embeds = []
         for msg in news['messages']:
             embed = NewsEmbed(msg,news['updated'])
             self.embeds.append(embed)
     else:
         self.content = localisation.getFormattedMessage('news_error',author=msg.author.id,lang=locale)
示例#10
0
 def run(self,client,command,msg,settings):
     locale = settings.get('locale')
     if command.count('"') > 1:
         command = command[command.index('"')+1:]
         prefix = command[:command.index('"')]
     else:
         try:
             prefix = command.split(" ")[1]
         except IndexError:
             prefix = ''
     if prefix != '':
         text = localisation.getFormattedMessage('setprefix_confirm',author=msg.author.id,prefix=prefix,lang=locale)
         self.custom = modals.AcceptModal(client,content=text,accept=self.acceptModal,decline=self.declineModal,only=msg.author)
         self.custom.prefix = prefix
         self.custom.locale = locale
         yield from self.custom.send(msg.channel)
         # self.content = '<@!{0}> Successfully set the prefix to `{1}`'.format(msg.author.id,prefix)
         # self.settings = {'prefix':prefix}
     else:
         self.content = localisation.getFormattedMessage('setprefix_invalid',author=msg.author.id,lang=locale)
示例#11
0
def autocheatsheets(client):
    logger = logging.getLogger('autosheets')
    yield from client.wait_until_ready()
    logger.info('Autosheets started')
    while not client.is_closed:
        update_time = 600
        cache = client.database.get_cache('last_cheat_sheet',once=True)
        if cache is None:
            cache = {'season':0,'week':0}
        else:
            try:
                cache = json.loads(cache.get('last_cheat_sheet'))
            except:
                logger.debug(str(cache))
                cache = {'season':0,'week':0}
        old_cache = dict(cache)
        update = None
        data = yield from cheatsheets.get_cheat_sheets()
        for sheet in data:
            if ((sheet.season >= cache.get('season',0) and sheet.week > cache.get('week',0)) or sheet.season > cache.get('season',0)) and sheet.has_image:
                cache['season'] = sheet.season
                cache['week'] = sheet.week
                update = sheet
        if old_cache.get('season') != cache.get('season') or old_cache.get('week') != cache.get('week'):
            try:
                client.database.set_cache('last_cheat_sheet',json.dumps(cache),once=True)
                logger.info('Updated cache')
            except:
                error = traceback.format_exc()
                logger.error('Error updating cache: %s',error)
        else:
            logger.debug('%s\n%s',str(old_cache),str(cache))
        if update is not None:
            title = localisation.getFormattedMessage('autocheatsheets_title',season=update.season,week=update.week)
            description = localisation.getMessage('autocheatsheets_desc')
            embed = discord.Embed(title=title,description=description,color=0xe67e22)
            embed.set_image(url=update.image)
            logger.info('Embed built {0}.{1} image url: {2}'.format(update.season,update.week,update.image))
            servers = yield from get_server_priority(list(client.servers),client.database.get_priority_servers)
            for servers_r in servers:
                for serverd in servers_r:
                    serverid = serverd.id
                    server = client.database.server_info(serverid,channels=True)
                    if 'autocheatsheets' in server.get('channels',[]):
                        try:
                            yield from client.send_message(discord.Object(server['channels']['autocheatsheets']),embed=embed)
                        except:
                            error = traceback.format_exc()
                            logger.error('Unabled to send cheat sheet: %s',error)
                        update_time -= RATE_LIMIT_TIME
                        yield from asyncio.sleep(RATE_LIMIT_TIME)
        logger.info('Auto cheat sheets update complete checking again in %s', parse_second_time(update_time))
        if update_time > 0:
            yield from asyncio.sleep(update_time)
示例#12
0
 def run(self,client,command,msg,settings):
     locale = settings.get('locale')
     channelid = msg.channel.id
     try:
         type = command.split(" ")[1].lower()
     except IndexError:
         type = ""
     success = False
     self.settings = {'channels':{}}
     if type == 'all':
         for channeltype in self.types:
             self.settings['channels'][channeltype] = channelid
         success = True
     else:
         for channeltype in self.types:
             if type == channeltype:
                 self.settings['channels'][channeltype] = channelid
                 success = True
     if success:
         self.content = localisation.getFormattedMessage('setchannel_success',author=msg.author.id,channel=channelid,type=type,lang=locale)
     else:
         typemsg = arrays.message_string(self.types,'all')
         self.content = localisation.getFormattedMessage('setchannel_error',author=msg.author.id,types=typemsg,lang=locale)
示例#13
0
 def __init__(self,locale=None):
     super().__init__(title=localisation.getMessage('setlocale_title',lang=locale),description=localisation.getMessage('setlocale_desc',lang=locale),color=0x6ad2f7)
     self.flags = {}
     locales = localisation.getLocales()
     for localeInfo in locales:
         if localeInfo.lang == 'en':
             country = 'GB'
         elif localeInfo.lang == 'pt-br':
             country = 'BR'
         else:
             country = localeInfo.lang
         flag = self.getFlag(country)
         self.flags[flag] = localeInfo.lang
         title = '{} {}'.format(flag,localeInfo.name)
         if localeInfo.name != localeInfo.nameEn:
             title += ' (' + localeInfo.nameEn + ')'
         value = localisation.getFormattedMessage('setlocale_value',lang=locale,author=localeInfo.author)
         self.add_field(name=title,value=value,inline=False)
示例#14
0
 def run(self,client,command,msg,settings):
     locale = settings.get('locale')
     logger = logging.getLogger('stats')
     if command.startswith('stats'):
         args = command[len('stats'):].strip()
     else:
         args = command.strip()
     type = 'regular'
     match = strings.startmatches(args, ['cs','currentseason'])
     if match is not None:
         args = args[len(match):].strip()
         type = 'curr_season'
     user = yield from parse_fortnite_user(args, msg.author.id, msg.server.id, self.sql)
     name = user.get('name')
     platform = user.get('platform')
     linked = user.get('linked')
     if len(name.strip()) > 0:
         try:
             logger.debug('Stats command name: %s platform %s', name, platform)
             bgs = settings.get('backgrounds',{})
             bgs_s = bgs.get('stat',[])
             if type == 'regular':
                 statsimage = yield from stats.generate(self.tn_key,name,platform,bgs_s)
             elif type == 'curr_season':
                 statsimage = yield from stats.generate_season(self.tn_key,name,platform,bgs_s)
             if statsimage is None:
                 if linked:
                     self.content = localisation.getFormattedMessage('stats_notfound_link',username=name,platform=platform,lang=locale)
                 else:
                     self.content = localisation.getFormattedMessage('stats_notfound',username=name,platform=platform,lang=locale)
                     if platform != 'pc':
                         self.content += localisation.getMessage('stats_notfound_console',lang=locale)
             else:
                 self.typing = True
                 statsimage.save('generatedstats.png')
                 self.content = '<https://{}>'.format(urllib.parse.quote('fortnitetracker.com/profile/{1}/{0}'.format(name,platform)))
                 self.file = 'generatedstats.png'
         except Exception as e:
             if linked:
                 self.content = localisation.getFormattedMessage('stats_error_link',username=name,platform=platform,lang=locale)
             else:
                 self.content = localisation.getFormattedMessage('stats_error',username=name,platform=platform,lang=locale)
             logger.error(traceback.format_exc())
     else:
         if linked:
             self.content = localisation.getFormattedMessage('stats_short_link',username=name,platform=platform,lang=locale)
         else:
             self.content = localisation.getFormattedMessage('stats_short',author=msg.author.id,lang=locale)
     if name.find('shop') > -1 or name.find('help') > -1 or name.find('setprefix') > -1:
         self.content += localisation.getMessage('stats_command',lang=locale)
示例#15
0
def autoshop(client): # add fnbr not accessable fallback
    logger = logging.getLogger('autoshop')
    yield from client.wait_until_ready()
    logger.info('Autoshop started')
    while not client.is_closed:
        servers = yield from get_server_priority(list(client.servers),client.database.get_priority_servers)
        needRestart = False
        for servers_r in servers:
            if needRestart:
                break
            for serverd in servers_r:
                serverid = serverd.id
                server = client.database.server_info(serverid,backgrounds=True,channels=True)
                if 'autoshop' in server['channels']:
                    locale = server.get('locale')
                    now = time.time()
                    nextshop = server.get('next_shop')
                    if nextshop is None:
                        nextshop = time.mktime(datetime.now().utctimetuple())
                    if now >= nextshop:
                        bgs = server.get('backgrounds',{})
                        bgs_s = bgs.get('shop',[])
                        try:
                            file = yield from shop.generate(KEY_FNBR,serverid,bgs_s)
                        except:
                            error = traceback.format_exc()
                            logger.error('Error generating image: %s',error)
                            needRestart = True
                            break
                        content = localisation.getMessage('autoshop',lang=locale)
                        nextshoptime = tommorow()
                        try:
                            yield from client.send_file(discord.Object(server['channels']['autoshop']),file,content=content)
                            client.database.set_server_info(serverid,next_shop=nextshoptime,latest_shop=file)
                        except (discord.errors.Forbidden, discord.errors.NotFound):
                            logger.info('Forbidden or not found on server: {}'.format(serverid))
                            serverdata = client.get_server(serverid)
                            if serverdata is None:
                                client.database.delete_server(serverid)
                            else:
                                try:
                                    client.database.set_server_info(serverid,next_shop=nextshoptime,latest_shop=file)
                                    client.database.set_server_channel(serverid,'autoshop',None)
                                except:
                                    error = traceback.format_exc()
                                    logger.error('Error updating database: {0}'.format(error))
                                try:
                                    text = localisation.getFormattedMessage('autoshop_no_access',channel=server['channels']['autoshop'],server_name=serverdata.name,lang=locale)
                                    yield from client.send_message(serverdata.owner,content=text)
                                except:
                                    error = traceback.format_exc()
                                    logger.error('Error sending message to owner: {0}'.format(error))
                        except:
                            error = traceback.format_exc()
                            logger.error('Error sending shop: %s', error)
                        yield from asyncio.sleep(RATE_LIMIT_TIME)
            time_until_next = nextshop-now
            if time_until_next < 0:
                time_until_next = 1
            else:
                time_until_next += 10
        logger.info("Autoshop now:%d next:%d updating in: %s", now, nextshop, parse_second_time(nextshop-now))
        yield from asyncio.sleep(time_until_next)