async def on_reaction_add(self, reaction, user): server = config[str(user.guild.id)] tally = 0 if user == self.bot.user: return if not reaction.message.channel.id == 137233143194320896: return db.try_create_table(f'pins_{user.guild.id}', ('message', 'users')) if not reaction.emoji == server['autopin']['reaction'] or reaction.message.pinned: return if reaction.message.id not in db.query(f'select message from pins_{user.guild.id}'): db.insert(f'pins_{user.guild.id}', (reaction.message.id, user.id)) await reaction.message.add_reaction(reaction.emoji) else: users = db.query(f'select users from pins_{user.guild.id} where message = {reaction.message.id}') if user.id not in users: tally = len(db.query(f'select users from pins_{user.guild.id} where message = {reaction.message.id}')) db.insert(f'pins_{user.guild.id}', (reaction.message.id, user.id)) await reaction.message.remove_reaction(reaction.emoji, user) if tally == server['autopin']['threshold']: await reaction.message.pin() db.remove(f'pins_{user.guild.id}', f'message = {reaction.message.id}')
async def fetch_platgod(self, ctx): """ Updates the copy of Platinum God stored in the database. Owner only. """ base_message = await ctx.send("Beginning loop.") platgods = [ 'original', 'rebirth', 'antibirth', 'afterbirth', 'afterbirth-plus' ] for base_url in platgods: await base_message.edit(content=f"Fetching...") soup = BeautifulSoup( requests.get(f"https://platinumgod.co.uk/{base_url}").content, 'html.parser') items = soup.find(class_="main").find_all(class_="item-title") db.drop_table(f'platgod_{base_url.replace("-", "")}') db.try_create_table(f'platgod_{base_url.replace("-", "")}', ('item', 'detail')) await base_message.edit(content=f"Saving {base_url} to database.") for item in items: item_title = item.text details = item.parent.find_all("p") for detail in details: if "tags" not in str(detail) and str(detail): if not "birth Pills" in item_title.replace("+", ""): print( f'{base_url} insert into platgod_{base_url.replace("-", "")} values (?, ?)', (item_title, detail.text)) db.c.execute( f'insert into platgod_{base_url.replace("-", "")} values (?, ?)', (item_title, detail.text)) db.conn.commit() await base_message.edit(content="Finished.")
async def strike(self, ctx, users: commands.Greedy[discord.Member], time: str, *, reason: str=None): """ Strikes a user, leaving a mark on the record. A 24 hour probation is automatically applied. Strikes will be removed from the record after a set time period, if provided. Examples: .strike @jerb#6464 1w spam """ server = config[str(ctx.guild.id)] if await parse_time(time): delta = await parse_time(time) time = datetime.datetime.now() + delta time = time.timestamp() if isinstance(time, str): reason = f'{time} {reason}'.rstrip() if reason else time db.try_create_table(f'strikes_{ctx.guild.id}', ('id', 'issuer', 'reason', 'time')) for user in users: try: await remove_task(f'probation_{ctx.guild.id}_{user.id}') except JobLookupError: pass #TODO proper error handling await probate_user(user, "24h", reason) db.insert(f'strikes_{ctx.guild.id}', (user.id, ctx.author.id, reason, time if not isinstance(time, str) else "None")) amount = len(db.query(f'SELECT reason from strikes_{ctx.guild.id} WHERE id = {user.id}')) await write_embed(server['modlog_id'], member=None, color=server['strikes']['embed_color'], title=reason, event=ctx.author.name, avatar=False, message=f'**Strike issued:** {user.mention} has received strike {amount}. ' + (f'This strike will expire on ' f'{datetime.datetime.utcfromtimestamp(time).replace(microsecond=0)} UTC.' if not isinstance(time, str) else "")) base_message = f'You have been **striked** on {ctx.guild.name}. This is strike {amount}.\n' + \ f'The provided reason is `{reason}`. ' if not isinstance(time, str): base_message = base_message + f"\nThis strike is **temporary**, and is set to expire on " \ f"{datetime.datetime.utcfromtimestamp(time).replace(microsecond=0)} UTC. You will be removed from probation in 24 hours." scheduler.add_job(remove_strike, 'date', run_date=datetime.datetime.fromtimestamp(time), args=[ctx.guild.id, [user.id, ctx.author.id, reason, time]], id=f"strikeremoval_{server}_{time}") if server['strikes']['ban']['enabled'] and amount >= server['strikes']['ban']['amount']: await user.send(base_message + f'As this is strike {amount}, you have been automatically banned.') try: await remove_task(f'probation_{ctx.guild.id}_{user.id}') except JobLookupError: pass # TODO proper error handling await ctx.guild.ban(user, delete_message_days=0) elif server['strikes']['kick']['enabled'] and amount >= server['strikes']['kick']['amount']: await user.send(base_message + f'As this is strike {amount}, you have been automatically kicked.') try: await remove_task(f'probation_{ctx.guild.id}_{user.id}') except JobLookupError: pass # TODO proper error handling await ctx.guild.kick(user) else: await user.send(base_message) await ctx.send(f'{list_prettyprint(user.name for user in users)} striked.')
async def on_message(self, message): server_id = str(message.guild.id) if not message.guild.id == 123641386921754625 or message.author == self.bot.user: return db.try_create_table('items_progress', ('user', 'amount', 'progress')) try: #if True: db.update( 'items_progress', f'amount = {db.query(f"select amount from items_progress where user = {message.author.id}")[0] + 1} ' f'where user = {message.author.id}') except Exception as e: db.insert('items_progress', (message.author.id, 1, 0)) try: await remove_task(f"items_{message.author.id}") except: pass await schedule_task(self.evaluate_items, timedelta(minutes=10), f"items_{message.author.id}", [message.author.id]) if message.channel.id == 294885337262456832 or message.channel.id == 290882932636254210: if message.content.lower() == "i am pure": for role in self.roles: await message.author.remove_roles( discord.utils.get(message.guild.roles, id=role[3])) await message.channel.send("**You are cleansed.**") for role in self.roles: if message.content.lower() in [text for text in role[0]]: amount = len( db.query( f"select item from received_items where user = {message.author.id}" )) roles = message.author.roles try: if role[4] in [role.id for role in roles]: await message.channel.send( "You already chose your fate.") return except IndexError: pass if amount >= role[1]: await message.channel.send(role[2]) await message.author.add_roles( discord.utils.get(message.guild.roles, id=role[3])) else: await message.channel.send( f"You need **{role[1] - amount}** more items!")
async def watch(self, ctx, users: commands.Greedy[discord.Member], *, reason: typing.Optional[str] = ''): """ Adds problematic users to the watchlist. """ db.try_create_table(f'eagleeye_{ctx.guild.id}', ('id', 'username', 'reason')) for user in users: db.insert( f'eagleeye_{ctx.guild.id}', (int(user.id), self.bot.get_user(int(user.id)).name, reason)) await ctx.send( f'{list_prettyprint(user.name for user in users)} added to the watchlist.' )
async def award_item(self, user): db.update('items_progress', f'progress = 0 where user = {user}') db.try_create_table("received_items", ('user', 'dlc', 'item')) award_dlcs = db.query( f'select dlc from items where item not in (select item from received_items where user = {user});' ) award_items = db.query( f'select item from items where item not in (select item from received_items where user = {user});' ) award = randint(0, len(award_dlcs) - 1) try: # necessary in case the user blocks the bot / has friends-only dm's await discord.utils.get(self.bot.users, id=user).send( f":crown: You just found {award_items[award]}!\n") except: pass await self.bot.get_channel(193042852819894272).send( f"<@{user}> just found {award_items[award]}!") db.insert("received_items", (user, award_dlcs[award], award_items[award]))
async def probate_user(user, time, reason): timedelta = await parse_time(time) db.try_create_table(f'probations_{user.guild.id}', ('id', 'reason', 'time')) category = discord.utils.get(user.guild.categories, name="Probations") role = discord.utils.get(user.guild.roles, name=config[str( user.guild.id)]['probate']['role_name']) channel = discord.utils.get(user.guild.channels, name=f'probation_{user.id}') overwrites = { user.guild.default_role: discord.PermissionOverwrite(read_messages=False), user.guild.me: discord.PermissionOverwrite(read_messages=True), } for staff_role in config[str(user.guild.id)]['probate']['roles']: staff_role = discord.utils.get(user.guild.roles, name=staff_role) overwrites[staff_role] = discord.PermissionOverwrite( read_messages=True) if not category: category_overwrites = overwrites category_overwrites[role] = discord.PermissionOverwrite( read_messages=False) category = await user.guild.create_category( "Probations", overwrites=category_overwrites) overwrites[user] = discord.PermissionOverwrite(read_messages=True) if not channel: channel = await user.guild.create_text_channel( f'probation_{user.id}', overwrites=overwrites, category=category, topic=f'{user.mention} - {time} - {reason}') else: await channel.set_permissions( user, overwrite=discord.PermissionOverwrite(read_messages=True)) try: await schedule_task(unprobate_user, timedelta, f'probation_{user.guild.id}_{user.id}', [user]) except: pass db.insert(f'probations_{user.guild.id}', (user.id, reason, time)) await user.add_roles(role)