async def check_empty_bp(self, ctx): """ Yet another ST only command. Returns a DM with a list of players\n\ who have 0 blood points. """ authorized = False guild = db.get_guild_info(ctx.guild.id) for role in ctx.author.roles: if guild.get("st_id") == role.id: authorized = True if authorized: db.execute( "SELECT player_id from Characters WHERE bp = 0 AND guild_id = %s", guild.get("id"), ) player_list = db.c.fetchall() i = 0 zeros_message = "" while i < len(player_list): zeros_message += ( ctx.guild.get_member(int(player_list[i][0])).display_name + "\n" ) i += 1 await ctx.author.send(f"Players with 0 Blood Points:\n{zeros_message}") else: await ctx.send("Error: Insufficient permissions.")
async def chess_leave(self, ctx): player = db.get_player_info(ctx.guild.id, ctx.author.id) db.execute("UPDATE Characters SET chess = 0 WHERE id = %s", (player.get('id'), )) await ctx.send( f"{ctx.author.display_name} has been removed from the chess queue." )
async def add_player(self, ctx, member: discord.Member): """ Adds a blank entry for the mentioned Discord user. """ authorized = False guild = db.get_guild_info(ctx.guild.id) for role in ctx.author.roles: if guild.get("st_id") == role.id: authorized = True elif guild.get("narrator_id") == role.id: authorized = True if authorized: try: exist_check = db.get_player_info(ctx.guild.id, member.id) except TypeError: db.execute( "INSERT INTO Characters (player_id, bp_max, bp, wp_max, wp, upkeep, upkeep_dt, agg_dmg, " "alert_flag, guild_id, active_toggle, Experience) VALUES (%s,5,5,5,5,0,' ', 0,0,%s, 0, 0)", (member.id, guild.get("id")), ) await ctx.send("Player Added") else: await ctx.send( "Player is already in the database for this server. Please remove them first." )
async def stake(self, ctx): guild = db.get_guild_info(ctx.guild.id) counter = guild.get("stakes") db.execute( "UPDATE Config SET stakes = %s WHERE id = %s", (counter + 1, guild.get("id")), ) await ctx.send( f"*Gets frozen in place.* **Dracula has been staked: {counter + 1} times!**" )
async def set_exp(self, ctx, member, value): authorized = False guild = db.get_guild_info(ctx.guild.id) for role in ctx.author.roles: if guild.get("st_id") == role.id: authorized = True if authorized: db.execute("UPDATE Characters SET Experience = %s WHERE player_id = %s", (int(value), int(member))) await ctx.send("Experience set successfully.")
async def add_exp(self, ctx, member, value): authorized = False guild = db.get_guild_info(ctx.guild.id) for role in ctx.author.roles: if guild.get("st_id") == role.id: authorized = True if authorized: player = db.get_player_info(ctx.guild.id, int(member)) new_exp = player.get('experience') + int(value) db.execute("UPDATE Characters SET Experience = %s WHERE player_id = %s", (new_exp, player.get('player_id'))) await ctx.send("Experience added successfully.")
async def chess_new(self, ctx): player = db.get_player_info(ctx.guild.id, ctx.author.id) players = db.get_all_players(ctx.guild.id) exist_check = 0 for person in players: if person.get('chess') == ctx.channel.id: exist_check = 1 if player.get('chess') == 0 and exist_check == 0: db.execute( "UPDATE Characters SET chess = %s WHERE id = %s", (ctx.channel.id, player.get('id')), ) await ctx.send("Game lobby created successfully.")
async def chess_join(self, ctx): players = db.get_all_players(ctx.guild.id) for player in players: if player.get('chess') == ctx.channel.id: p1 = ctx.guild.get_member(player.get('player_id')).display_name p2 = ctx.author.display_name user = db.get_player_info(ctx.guild.id, ctx.author.id) await ctx.send( f"Game prepared in this channel for players: {p1} and {p2}." ) db.execute( "UPDATE Characters SET chess = %s WHERE id = %s", (ctx.channel.id, user.get('id')), )
async def add_exp_role(self, ctx, role_added: discord.Role, value): authorized = False guild = db.get_guild_info(ctx.guild.id) for role in ctx.author.roles: if guild.get("st_id") == role.id: authorized = True if authorized: r_list = role_added.members print(r_list) for member in r_list: player = db.get_player_info(ctx.guild.id, member.id) new_exp = player.get('experience') + int(value) db.execute("UPDATE Characters SET Experience = %s WHERE player_id = %s AND guild_id = %s", (new_exp, player.get('player_id'), player.get('guild_id'))) await ctx.send("Experience added successfully.")
async def rm_player(self, ctx, member): """ Removes specified user from Blood and Willpower database.\n\ Syntax: $rm_player [member] """ authorized = False guild = db.get_guild_info(ctx.guild.id) for role in ctx.author.roles: if guild.get("st_id") == role.id: authorized = True elif guild.get("narrator_id") == role.id: authorized = True if authorized: db.execute( "DELETE FROM Characters WHERE player_id = %s AND guild_id = %s", (int(member), guild.get("id")), ) await ctx.send("Value updated.")
async def set_bp_upkeep(self, ctx, member: discord.Member, value): """ Sets bp upkeep value of the specified member to the specified value (ST / Narrator only command).\n\ Syntax: $set_bp_upkeep [member] [value] """ authorized = False guild = db.get_guild_info(ctx.guild.id) for role in ctx.author.roles: if guild.get("st_id") == role.id: authorized = True elif guild.get("narrator_id") == role.id: authorized = True if authorized: db.execute( "UPDATE Characters SET upkeep = %s WHERE player_id = %s AND guild_id = %s", (value, member.id, guild.get("id")), ) await ctx.send("Value updated.")
async def set_wp(self, ctx, member: discord.Member, value): """ Sets WP value of the specified member to the specified value (ST / Narrator only command).\n\ Syntax: $set_wp [member] [value]\n\ NOTE: This does not check WP max values, so through this command one may exceed WP limits. """ authorized = False guild = db.get_guild_info(ctx.guild.id) for role in ctx.author.roles: if guild.get("st_id") == role.id: authorized = True elif guild.get("narrator_id") == role.id: authorized = True if authorized: db.execute( "UPDATE Characters SET wp = %s WHERE player_id = %s AND guild_id = %s", (value, member.id, guild.get("id")), ) await ctx.send("Value updated.")
async def purge_bp_leavers(self, ctx): """ Another ST only command. Goes through list of users and flags\n\ ones to keep in the database from those still in server, purging the leavers. """ authorized = False guild = db.get_guild_info(ctx.guild.id) for role in ctx.author.roles: if guild.get("st_id") == role.id: authorized = True if authorized: player_list = db.get_all_players(ctx.guild.id) for player in player_list: d_player = ctx.guild.get_member(player.get("player_id")) if d_player: if d_player in ctx.guild.get_role(guild.get("player_role")).members: db.execute( "UPDATE Characters SET active_toggle = 1 WHERE id = %s", player.get("id"), ) db.execute( "DELETE FROM Characters WHERE active_toggle = 0 AND guild_id = %s", guild.get("id"), ) db.execute("UPDATE Characters SET active_toggle = 0") await ctx.send("Table updated.")
async def blood_bag(self): for guild in db.get_guild_list(): guild = db.get_guild_info(guild[0]) bb_role = self.bot.get_guild(guild.get("guild_id")).get_role( guild.get("bb_id") ) bb_members = bb_role.members if bb_members is not None: for member in bb_members: try: player = db.get_player_info(guild.get("guild_id"), member.id) if player.get("bp") + 1 <= player.get("bp_max"): await self.bot.get_guild(guild.get("guild_id")).get_member( member.id ).remove_roles(bb_role) new_bp = player.get("bp") + 1 db.execute( "UPDATE Characters SET bp = %s WHERE id = %s", (new_bp, player.get("id")), ) except TypeError: continue
async def bp_wp_pop(self, ctx): """ Populates BP/WP database with users in-server. (ST only command)\n\ Does not affect those who already have entries in the table.\n\ Will set all values other than their player_id to 0. """ authorized = False guild = db.get_guild_info(ctx.guild.id) for role in ctx.author.roles: if guild.get("st_id") == role.id: authorized = True if authorized: for member in ctx.guild.members: if guild.get("player_role") in member.roles: try: exist_check = db.get_player_info(ctx.guild.id, member.id) except TypeError: db.execute( "INSERT INTO Characters (player_id, bp_max, bp, wp_max, wp, upkeep," "agg_dmg, alert_flag, guild_id) VALUES (%s,5,5,5,5,0,' ', 0,0,%s, 0, 0)", (member.id, guild.get("id")), ) await ctx.send("Table populated.")
async def daily_commands(self): for guild_id in db.get_guild_list(): guild_id = guild_id[0] cur_date_dt = time.ic_date_dt(guild_id) guild = db.get_guild_info(guild_id) last_date = guild.get("last_date") player_list = db.get_all_players(guild_id) for player in player_list: if not self.bot.get_user(player.get("player_id")): db.execute("DELETE FROM Characters WHERE id = %s", (player.get("id"), )) else: if player.get("bp") == 0 and player.get("alert_flag") == 0: db.execute( "UPDATE Characters SET alert_flag = 1 WHERE id = %s", (player.get("id"), ), ) try: guild_name = self.bot.get_guild(guild_id).name await self.bot.get_user( player.get("player_id") ).send(f"Your character is at 0 BP due to " f"infrequent feeding or inactivity. " f"If your character remains on this " f"list too long you risk being " f"removed from {guild_name}. When " f"you log in please fill free to " f"roll as many time as are " f"necessary to fill your " f"character's blood pool. You may " f"then jump into play without " f"accounting as the feeding " f"occurred while you were offline.") except KeyError: continue if player.get("alert_flag") == 1 and player.get("bp") > 0: db.execute( "UPDATE Characters SET alert_flag = 0 WHERE id = %s", (player.get("id"), ), ) if player.get("upkeep") > 0: time.ic_datetime_utc(guild_id) ctime = time.ic_datetime_utc(guild_id) if player.get("upkeep_date") != " ": old_upkeep = utc.localize( player.get("upkeep_date")) else: old_upkeep = time.ic_datetime_utc(guild_id) db.execute( "UPDATE Characters SET upkeep_dt = %s WHERE id = %s", ( old_upkeep.strftime("%Y:%m:%d:%H:%M:%S"), player.get("id"), ), ) if old_upkeep < ctime: new_bp = player.get("bp") - 1 upkeep_datetime = old_upkeep + timedelta( days=30.4375 / player.get("upkeep")) db.execute( "UPDATE Characters SET upkeep_dt = %s, bp = %s WHERE id = %s", ( upkeep_datetime.strftime( "%Y:%m:%d:%H:%M:%S"), new_bp, player.get("id"), ), ) if cur_date_dt != last_date: cur_date = time.ic_date(guild_id) channel = self.bot.get_guild(guild_id).get_channel( guild.get("date_chan")) await channel.send("The date is now: " + cur_date + ". Your hunger grows.") db.execute( "UPDATE Config SET last_date = %s WHERE guild_id = %s", (cur_date_dt.strftime("%Y:%m:%d"), guild_id), ) player_list = db.get_all_players(guild_id) for player in player_list: current_bp = player.get("bp") - 1 if current_bp >= 0: db.execute( "UPDATE Characters SET bp = %s WHERE id = %s", (current_bp, player.get("id")), ) current_wp = player.get("wp") current_wp_max = player.get("wp_max") if current_wp < current_wp_max: current_wp += 1 db.execute( "UPDATE Characters SET wp = %s WHERE id = %s", (current_wp, player.get("id")), )
async def rs(self, ctx, pool: int = 1, diff: int = 6, wp: str = "0", *reason): """ Same as $r except this also applies explosions to the dice.\n\ Syntax: $rs [Dice Pool] [Difficulty] [wpifier]\n\ \n\ Example: $rs 5 7 => [10, 2, 8, 4, 3] [9] Results: 3 Successes! """ st_alert = 0 reason_string = "" if pool < 1: pass elif diff < 1: pass else: reason = list(reason) try: wp = int(wp) except ValueError: reason.insert(0, wp) wp = 0 if not reason: reason = ["No reason provided."] for word in reason: reason_string += word + " " reason_string = reason_string[:-1] ss = 0 fail = 0 tens = 0 random_raw = [] for i in range(pool): random_raw.append(random.randint(1, 10)) await ctx.send(random_raw) for roll in random_raw: if roll >= diff: ss += 1 elif roll == 1: fail += 1 if roll == 10: tens += 1 guild = db.get_guild_info(ctx.guild.id) if guild.get("exploding_toggle") == 1: if ss <= 0 and wp <= 0: if fail > 0: result = "Botch! | Reason: " + str(reason_string) st_alert = 2 else: result = "Failure! | Reason: " + str(reason_string) st_alert = 1 else: ss -= fail tens -= fail while tens > 0: explosion = [] for i in range(tens): explosion.append(random.randint(1, 10)) await ctx.send(explosion) ten = 0 for roll in explosion: if roll == 10: ten += 1 ss += 1 elif roll >= diff: ss += 1 tens = ten if ss <= 0: ss = wp else: ss += wp if ss <= 0: result = "Failure! | Reason: " + str(reason_string) st_alert = 1 else: result = str(ss) + " Successes! | Reason: " + str(reason_string) elif guild.get("exploding_toggle") == 0: ss += tens ss -= fail if ss <= 0: ss = wp else: ss += wp if ss <= 0: result = "Failure! | Reason: " + str(reason_string) st_alert = 1 else: result = str(ss) + " Successes! | Reason: " + str(reason_string) await ctx.send("{} - Results: ".format(ctx.author.mention) + result) if ctx.channel.id == guild.get("feeding_chan"): net_ss = ss - fail if net_ss < 0: net_ss = wp player = db.get_player_info(ctx.guild.id, ctx.author.id) current_bp = player.get("bp") bp_max = player.get("bp_max") new_bp = current_bp + net_ss if new_bp > bp_max: new_bp = bp_max db.execute( "UPDATE Characters SET bp = %s WHERE id = %s", (new_bp, player.get("id")), ) if st_alert == 1: await self.bot.get_channel(guild.get("st_alerts_chan")).send( "{} failed a feeding roll!".format(ctx.author.mention) ) elif st_alert == 2: await self.bot.get_channel(guild.get("st_alerts_chan")).send( "{} botched a feeding roll!".format(ctx.author.mention) )
async def r(self, ctx, pool: int = 1, diff: int = 6, wp: str = "0", *reason): """ Rolls and checks successes.\n\ Syntax: $r [Dice Pool] [Difficulty] [modifier]\n\ \n\ Example: $r 5 7 => [5, 2, 8, 4, 3] Results: 1 Successes! """ alert_st = 0 reason_string = "" if pool < 1: pass elif diff < 1: pass else: reason = list(reason) try: wp = int(wp) except ValueError: reason.insert(0, wp) wp = 0 if not reason: reason = ["No reason provided."] for word in reason: reason_string += word + " " reason_string = reason_string[:-1] ss = 0 fail = 0 random_raw = [] for i in range(pool): random_raw.append(random.randint(1, 10)) await ctx.send(random_raw) for roll in random_raw: if roll >= diff: ss += 1 if roll == 1: fail += 1 if ss <= 0 and wp <= 0: if fail > 0: result = "Botch! | Reason: " + str(reason_string) alert_st = 2 else: result = "Failure! | Reason: " + str(reason_string) alert_st = 1 elif ss - fail <= 0 < ss and wp <= 0: result = "Failure! | Reason: " + str(reason_string) alert_st = 1 else: ss += wp if ss - fail > 0: result = ( str(ss - fail) + " successes! | Reason: " + str(reason_string) ) else: result = ( "{} successes!".format(str(wp)) + " | Reason: " + str(reason_string) ) await ctx.send("{} - Results: ".format(ctx.author.mention) + result) guild = db.get_guild_info(ctx.guild.id) if ctx.channel.id == guild.get("feeding_chan"): net_ss = ss - fail if net_ss < 0: net_ss = wp player = db.get_player_info(ctx.guild.id, ctx.author.id) current_bp = player.get("bp") bp_max = player.get("bp_max") new_bp = current_bp + net_ss if new_bp > bp_max: new_bp = bp_max db.execute( "UPDATE Characters SET bp = %s WHERE id = %s", (new_bp, player.get("id")), ) if alert_st == 1: await self.bot.get_channel(guild.get("st_alerts_chan")).send( "{} failed a feeding roll!".format(ctx.author.mention) ) elif alert_st == 2: await self.bot.get_channel(guild.get("st_alerts_chan")).send( "{} botched a feeding roll!".format(ctx.author.mention) )
async def wp(self, ctx, arg1="none", arg2="none"): """ WP checking and expenditure for all!\n\n\ There's two versions of this command:\n\ [+] All players - $wp checks WP level and DMs you, $wp [value] spends [value] BP\n\ [+] STs and Narrators - $wp [user] checks their WP and DMs you, $wp [user] [value] works similarly. """ if arg1 == "none": player = db.get_player_info(ctx.guild.id, ctx.author.id) await ctx.author.send( f"{ctx.author.mention}'s Willpower: {player.get('wp')}" ) else: user_id = None try: arg1 = int(arg1) if arg1 < 0: await ctx.send("Error: Cannot spend negative WP.") elif arg1 < 100: mod = arg1 player = db.get_player_info(ctx.guild.id, ctx.author.id) if mod > player.get("wp"): await ctx.send("Error: Cannot spend WP in excess of pool.") else: mod = player.get("wp") - mod db.execute( "UPDATE Characters SET wp = %s WHERE id = %s", (mod, player.get("id")), ) await ctx.send("Values updated.") else: user_id = arg1 except ValueError: try: uid = self.bot.get_user(int(arg1[2:-1])).id if uid is None: await ctx.send("Error: Invalid syntax.") else: user_id = uid except ValueError: await ctx.send("Error: Invalid syntax.") if user_id is not None: authorized = False guild = db.get_guild_info(ctx.guild.id) for role in ctx.author.roles: if guild.get("st_id") == role.id: authorized = True elif guild.get("narrator_id") == role.id: authorized = True if authorized: if arg2 == "none": player = db.get_player_info(ctx.guild.id, user_id) await ctx.author.send( f"{self.bot.get_user(user_id).mention}'s Willpower: {player.get('wp')}" ) else: try: mod = int(arg2) if mod < 0: await ctx.send("Error: Cannot spend negative WP.") else: player = db.get_player_info(ctx.guild.id, user_id) if mod > player.get("wp"): await ctx.send( "Error: Cannot spend WP in excess of pool." ) else: mod = player.get("wp") - mod db.execute( "UPDATE Characters SET wp = %s WHERE id = %s", (mod, player.get("id")), ) await ctx.send("Values updated.") except ValueError: await ctx.send("Error: Invalid syntax.")