async def reset_silence(self): await self.bot.wait_until_ready() while not self.bot.is_closed(): to_be_deleted = [] self.cursor.execute("SELECT * FROM silenced") result = self.cursor.fetchall() for r in result: if r[2] < time.time(): guild = None for test_guild in self.bot.guilds: if test_guild.name == "Door Monster": guild = test_guild if guild is not None: member = guild.get_member(r[0]) if member is not None: await member.remove_roles( discord.utils.get(guild.roles, name="Silenced")) log("User unsilenced", member, None, r[1], None) mod_channel = self.bot.get_channel( 701870289491067001) await mod_channel.send( "<@&701867961769525329> User {} has been un-silenced" .format(member.name)) to_be_deleted.append(r[0]) for authorID in to_be_deleted: self.cursor.execute( "DELETE FROM silenced WHERE authorID={0}".format(authorID)) self.connection.commit() await asyncio.sleep(.5)
async def handle_discordauth_get(self, request): if self.request_open == 0: print('Invalid subscription request') return web.Response(status=404) log('Valid sub request to discord subscribers on wobsite', None, None, None, None) self.request_open = self.request_open - 1 return web.Response(body=request.query['challengeKey'])
async def handle_youtube_get(self, request): if request.query['hub.topic'] not in sub_channels or request.query[ 'hub.mode'] is 'unsubscribe' or self.request_open == 0: print('Invalid subscription request') return web.Response(status=404) log('Valid sub request to {}'.format(request.query['hub.topic']), None, None, None, None) self.request_open = self.request_open - 1 return web.Response(body=request.query['hub.challenge'])
async def massdel(self, ctx, numbers): """Delete a lot of channel history [MOD ONLY]""" is_mod = False for role in ctx.message.author.roles: if role.name == "Moderators": is_mod = True if not is_mod: return await ctx.send( "**Error:** You do not have permission to use this command!") log("Mass delete init", ctx.author, ctx.channel, numbers, None) async for elem in ctx.channel.history(limit=int(numbers) + 1): log("Mass Delete", elem.author, elem.channel, elem.content, elem.created_at) await elem.delete()
async def handle_youtube_post(self, request): try: sha1_a = request.headers['X-Hub-Signature'] except: sha1_a = 0 body = await request.content.read() hmac_checker = hmac.new(self.secret.encode(), body, sha1) if hexlify(hmac_checker.digest()).decode("utf-8") != sha1_a[5:]: print("False packet alert!") return web.Response(status=200) full_feed = body.decode("utf-8") split_delim = ['<', '>'] regex_patterns = '|'.join(map(re.escape, split_delim)) parsed_feed = re.split(regex_patterns, full_feed) pos = 1 video_id = None published_date = None for elem in parsed_feed: if elem == 'yt:videoId': video_id = parsed_feed[pos] if elem == 'published': published_date = parsed_feed[pos] pos = pos + 1 if video_id and published_date: is_new = True video_link = 'https://www.youtube.com/watch?v={}'.format(video_id) video_list = open("postedVideos.txt", "r") for video_elem in video_list: if video_link in str(video_elem): is_new = False video_list.close() if published_date[:10] != time.strftime("%Y-%m-%d", time.gmtime()): is_new = False if is_new: await self.the_channel.send( ":clapper: **New Video Posted!**\n{0}".format(video_link)) video_list = open("postedVideos.txt", "a") video_list.write("{0}\n".format(video_link)) video_list.close() else: archive_feed(full_feed) if video_id: log("Error, could not retreive published_date", None, None, None, None) elif published_date: log("Error, could not retreive videoId", None, None, None, None) else: log("Error, could not retreive videoId or published_date", None, None, None, None) return web.Response(status=200)
async def twitter_update(self): await self.bot.wait_until_ready() while not self.bot.is_closed(): try: recent = None twitter_client = PeonyClient( consumer_key=authDeets.consumer_key, consumer_secret=authDeets.consumer_secret, access_token=authDeets.access_token, access_token_secret=authDeets.access_token_secret) data = await twitter_client.api.statuses.user_timeline.get( screen_name='DoorMonster', count=1) recent = data[0]['id'] if recent: if self.last_twitter_update is None: self.last_twitter_update = recent print("Twitter link established, got tweet {}".format( recent)) if self.last_twitter_update != recent: self.last_twitter_update = recent if data[0][ 'in_reply_to_status_id'] is None and not data[ 0]['text'].startswith('RT @'): the_channel = discord.utils.get( self.bot.get_all_channels(), guild__name="Door Monster", name="social-media-feed") await the_channel.send( "https://twitter.com/DoorMonster/status/{0}". format(recent)) log("Twitter update", None, None, self.last_twitter_update, None) await asyncio.sleep(300) except: print("Error retreiving tweet, sleeping") await asyncio.sleep(3000)
async def silence(self, ctx, member_name: str, reason: str, *time_data: str): is_mod = False for role in ctx.message.author.roles: if role.name == "Moderators": is_mod = True if not is_mod: return await ctx.send( "**Error:** You are not allowed to use this command!") member = discord.utils.get(ctx.message.guild.members, name=member_name) if member is None: member = discord.utils.get(ctx.message.guild.members, nick=member_name) if member is None and len(ctx.message.mentions) is not 0: member = ctx.message.mentions[0] if member is None: return await ctx.send("**Error:** User not found") wait_time = 0 for time_datum in time_data: try: if time_datum[-1:] == "m": wait_time = wait_time + int(time_datum[:-1], 10) * 24 * 60 * 60 * 30 elif time_datum[-1:] == "w": wait_time = wait_time + int(time_datum[:-1], 10) * 24 * 60 * 60 * 7 elif time_datum[-1:] == "d": wait_time = wait_time + int(time_datum[:-1], 10) * 24 * 60 * 60 elif time_datum[-1:] == "h": wait_time = wait_time + int(time_datum[:-1], 10) * 60 * 60 elif time_datum[-1:] == "n": wait_time = wait_time + int(time_datum[:-1], 10) * 60 elif time_datum[-1:] == "s": wait_time = wait_time + int(time_datum[:-1], 10) else: await ctx.send( """**Error:** Correct usage is `.silence "user" "reason" <>m <>w <>d <>h <>n <>s`""" ) return except Exception: await ctx.send( """**Error:** Correct usage is `.silence "user" "reason" <>m <>w <>d <>h <>n <>s`""" ) return exp_time = wait_time + time.time() author_id = member.id self.cursor.execute("SELECT * FROM silenced") result = self.cursor.fetchall() for r in result: if r[0] == author_id: sql_command = """UPDATE silenced SET reason = "{1}", time = {2} WHERE authorID = {0};""".format( author_id, reason, exp_time) self.cursor.execute(sql_command) self.connection.commit() log("Silenced user update", member, None, reason, time.asctime(time.gmtime(exp_time))) if wait_time == 0: await member.send("Your silenced period has ended early") else: await member.send( "Your silenced period has been updated to last until {} UTC" .format(time.asctime(time.gmtime(exp_time)))) return await ctx.send( """{0}'s silenced period has been changed to {1} """. format(member_name, time.asctime(time.gmtime(exp_time)))) sql_command = """INSERT INTO silenced (authorID, reason, time) VALUES ({0}, "{1}", {2});""".format( author_id, reason, exp_time) log("User silenced", member, None, reason, time.asctime(time.gmtime(exp_time))) await member.add_roles( discord.utils.get(ctx.message.guild.roles, name="Silenced")) self.cursor.execute(sql_command) self.connection.commit() await member.send( "You have been silenced until {0} with the reason {1}\nContact a moderator for any questions" .format(time.asctime(time.gmtime(exp_time)), reason)) await ctx.send("""{0} has been silenced until {1}""".format( member_name, time.asctime(time.gmtime(exp_time))))