예제 #1
0
async def on_message(message):
    server = message.server

    if server is None:
        try:
            await oz.send_message(
                destination=message.author,
                content=f'Bạn vui lòng quay lại group **Cộng đồng MapleStory VN** và nhập lệnh `{oz.command_prefix}help` '
                'nhé. Xin cảm ơn :D')
        except HTTPException:
            pass
    else:
        role_request_channel = server.get_channel('453930352365273099')
        match_word_channel = ch.get_channel(server, id='458260628876951552')

        if message.channel == role_request_channel and message.content.startswith(oz.command_prefix):
            await oz.delete_message(message)

        # proc event
        elif message.channel == match_word_channel and message.content.startswith('>'):

            await match_word_event(message, match_word_channel, oz, event_db, valid_words)

        else:
            await oz.process_commands(message)
    async def parse(self):

        print('[GMS2 Site Spider] Waiting for ready state...')

        await self.bot.wait_until_ready()

        print('[GMS2 Site Spider] Ready and running!')

        self.channel = ch.get_channel(bot=self.bot, id=505584303154135040)

        while not self.bot.is_closed():

            # await asyncio.sleep(self.delay)

            checking_data = self.form_checking_data()
            site_datas = self.fetch_data()

            if not site_datas or not checking_data:
                await asyncio.sleep(self.delay)
                continue

            for data in site_datas:

                if (data['id'], data['title']) in checking_data:
                    continue

                embed = discord.Embed(
                    title=f"[{data['category']}] {data['title']}",
                    url=data['link'],
                    description=data['description'],
                    color=discord.Color.teal())
                embed.set_image(url=data['image'])

                try:
                    # send the message to channel
                    await self.bot.say_as_embed(channel=self.channel,
                                                embed=embed)

                    # save to drive and print the result title
                    self.sheet.insert_row([value for value in data.values()],
                                          index=2)
                except Exception:
                    continue

                print(f'Site Fetch: [GMS2] [Fetched {data["title"]}]')

                # updates the checking data
                checking_data = self.form_checking_data()

            await asyncio.sleep(self.delay)
예제 #3
0
    async def check_gmsm_schedule(self, delay=30):

        print('[GMSM Schedule Checker] Waiting for ready state...')

        await self.bot.wait_until_ready()

        print('[GMSM Schedule Checker] Ready and running!')

        server = self.bot.get_guild(id=453555802670759947)
        gmsm_noti_role = discord.utils.get(server.roles, name='Notify GMSM')

        while not self.bot.is_closed():
            # print('Schedule Check for GMSM: ...')
            try:
                schedule_db = self.db.worksheet('schedules_ms')
                data = schedule_db.get_all_records()
                for row_index, row in enumerate(data, start=2):
                    en = row['event_name'].lower()
                    # pass if posted
                    if row['posted']:
                        pass
                    # pass events of GMSM
                    elif en.startswith('[gms]') or en.startswith('.gms.'):
                        pass
                    elif en.startswith('[gmsm]') or en.startswith('.gmsm.'):
                        # parse and convert to UTC, order set to DMY
                        dt = dateparser.parse(row['date_time'], settings={'TIMEZONE': 'UTC', 'DATE_ORDER': 'DMY'})
                        # get UTC now and convert to timezone-aware
                        now = datetime.utcnow().replace(tzinfo=timezone('UTC'))

                        time_diff = (dt - now).total_seconds()
                        # event incoming, just pass
                        if time_diff > 0:
                            pass
                        # event has started
                        else:
                            # send the notification here!
                            channel = get_channel(bot=self.bot, id=461067191735943168)

                            tag_re = re.compile('(\[|\.)*gmsm(\]|\.)*\s*', re.IGNORECASE)
                            event_name = tag_re.sub('', row['event_name']).title()
                            await gmsm_noti_role.edit(mentionable=True)
                            await channel.send(f'{gmsm_noti_role.mention} {event_name}.')
                            await gmsm_noti_role.edit(mentionable=False)
                            schedule_db.update_cell(row_index, 3, 'x')
                            print(f'Schedule Check for GMSM: Posted `{event_name}` to channel {channel.id}')
            except APIError:
                pass
            # print('Schedule Check for GMSM: Done.')
            await asyncio.sleep(delay)
    async def parse(self):

        print('[GMSM Site Spider] Waiting for ready state...')

        await self.bot.wait_until_ready()

        print('[GMSM Site Spider] Ready and running!')
        self.channel = ch.get_channel(bot=self.bot, id=453565659637481472)

        while not self.bot.is_closed():

            # await asyncio.sleep(self.delay)
            checking_data = self.form_checking_data()
            site_datas = self.fetch_data()

            if not site_datas or not checking_data:
                await asyncio.sleep(self.delay)
                continue

            for data in site_datas:

                if (data['id'], data['title']) in checking_data:
                    continue

                embed = discord.Embed(
                    title=f"{data['label_vn']} - {data['title']}",
                    url=data['link'],
                    description=f"Cập nhật vào: {data['time']} {data['date']}",
                    color=discord.Color.teal())
                try:
                    # send the message to channel
                    await self.bot.say_as_embed(channel=self.channel,
                                                embed=embed)
                    # save to drive and print the result title
                    self.sheet.insert_row(list(data.values()), index=2)
                except Exception:
                    return

                print(f'Site Fetch: [GMSM] [Fetched {data["title"]}]')
                # updates the checking data
                checking_data = self.form_checking_data()

            await asyncio.sleep(self.delay)
예제 #5
0
    async def check_dawn_schedule(self, delay=30):

        print('[Dawn SAOMD Schedule Checker] Waiting for ready state...')

        await self.bot.wait_until_ready()

        print('[Dawn SAOMD Schedule Checker] Ready and running!')

        while not self.bot.is_closed():
            # print('Schedule Check for Dawn - SAOMD: ...')
            try:
                schedule_db = self.db.worksheet('schedules_saomd')
                data = schedule_db.get_all_records()
                for row_index, row in enumerate(data, start=2):
                        # pass if posted
                    if row['posted']:
                        pass
                    # pass events of GMSM
                    else:
                        # parse and convert to UTC, order set to DMY
                        dt = dateparser.parse(row['date_time'], settings={'TIMEZONE': 'UTC', 'DATE_ORDER': 'DMY'})
                        # get UTC now and convert to timezone-aware
                        now = datetime.utcnow().replace(tzinfo=timezone('UTC'))

                        time_diff = (dt - now).total_seconds()
                        # event incoming, just pass
                        if time_diff > 0:
                            pass
                        # event has started
                        else:
                            # send the notification here!
                            channel = get_channel(bot=self.bot, id=373663985368563717)

                            event_name = row['event_name'].title()
                            await channel.send(f'{event_name}.')
                            schedule_db.update_cell(row_index, 3, 'x')
                            print(f'Schedule Check for Dawn - SAOMD: Posted `{event_name}` to channel {channel.id}')
            except APIError:
                pass
            # print('Schedule Check for Dawn - SAOMD: Done.')
            await asyncio.sleep(delay)
예제 #6
0
    async def send_latest_status(self, user_id, channel_ids: list):
        """
        Send the latest status of given user_id, to the channel
        """

        # fetch the user_id twitter info
        tweet_count = 5
        try:
            latest_tweets = self.api.user_timeline(user_id, count=tweet_count)
        except tweepy.TweepError:
            return

        sheet, posted_ids = self.get_posted_ids(user_id)
        if not sheet or not posted_ids:
            return

        for tweet in latest_tweets:

            # build these things for later use
            u_screen_name = tweet.user.screen_name
            status_id = tweet.id_str

            # not retweet, not reply
            if not tweet.text.startswith(
                    'RT @') and not tweet.in_reply_to_user_id:
                proceed = True
            # reply to self
            elif user_id == tweet.in_reply_to_user_id:
                proceed = True
            else:
                proceed = False

            if proceed is False:
                continue

            if status_id in posted_ids:
                continue

            now = datetime.now()
            vn_tz = now.replace(tzinfo=timezone('Asia/Ho_Chi_Minh'))
            timestamp_date = vn_tz.strftime('%d/%m/%Y')
            timestamp_time = vn_tz.strftime('%H:%M:%S')

            sheet.insert_row([status_id, timestamp_date, timestamp_time],
                             index=2)

            # build the URL and save u_id and status_id for later use
            status_url = f'https://twitter.com/{u_screen_name}/status/{status_id}'

            # send the message to channel
            for channel_id in channel_ids:
                channel = ch.get_channel(bot=self.bot, id=channel_id)
                if not channel:
                    continue
                message = await channel.send(status_url)
                # try to auto-publish the message
                try:
                    await message.publish()
                except discord.Forbidden:
                    pass

            print(f'Twitter Fetch: [{u_screen_name}] [Fetched: {status_url}]')

            # updates the sheet and posted_ids
            sheet, posted_ids = self.get_posted_ids(user_id)
            if not sheet or not posted_ids:
                return