async def gameover(self, ctx): """ Remove all Simon Says roles """ simon_role = get(ctx.guild.roles, name=get_role("Simon")) player_role = get(ctx.guild.roles, name=get_role("Player")) loser_role = get(ctx.guild.roles, name=get_role("Loser")) giveaway_role = get(ctx.guild.roles, name=get_role("Giveaways")) total_members = 0 lines = [] for member in simon_role.members: await member.remove_roles(simon_role, giveaway_role) total_members += 1 lines.append( f"Removed {simon_role.mention} and {giveaway_role.mention} roles from {member}." ) for role in [player_role, loser_role]: members = 0 for member in role.members: await member.remove_roles(role) members += 1 if members != 0: total_members += members lines.append( f"Removed the {role.mention} role from {members} member(s)." ) if total_members == 0: lines.append(f"There were no roles to remove.") await ctx.send("", embed=gen_embed("Game Over", "\n".join(lines)))
async def revive(self, ctx, *users: Member): """ Revive users """ player_role = get(ctx.guild.roles, name=get_role("Player")) loser_role = get(ctx.guild.roles, name=get_role("Loser")) for user in users: await user.remove_roles(loser_role) await user.add_roles(player_role) await ctx.send("", embed=gen_embed("Revived user(s)."))
def adduser(): form = UserForm() if form.validate_on_submit(): fn = request.form['first_name'] ln = request.form['last_name'] new_user = User(id=request.form['UID'], name=fn + ' ' + ln, first_name=fn, last_name=ln, url=request.form['URL'], in_out=False, active=True) for role in Role.query.all(): if request.form.get(role.name): new_user.roles.append(get_role(role.name)) db.session.add(new_user) db.session.commit() return redirect(url_for('admin.userlist')) flash_errors(form) return render_template('admin/adduser.html', title=app.config['BASE_HTML_TITLE'], edit_mode=False, add_mode=True, roles=Role.query.all(), form=form)
async def setsimon(ctx, user: Member = None): """ Set a user as Simon """ if user == None: user = ctx.author simon_role = get(ctx.guild.roles, name=get_role("Simon")) player_role = get(ctx.guild.roles, name=get_role("Player")) loser_role = get(ctx.guild.roles, name=get_role("Loser")) giveaway_role = get(ctx.guild.roles, name=get_role("Giveaways")) await user.add_roles(simon_role, giveaway_role) await user.remove_roles(player_role, loser_role) await ctx.send("", embed=gen_embed("Updated Simon List", ", ".join(map(str, simon_role.members))))
async def remaining(ctx): """ Get the remaining Simon Says players """ player_role = get(ctx.guild.roles, name=get_role("Player")) title = f"{len(player_role.members)} Player(s) Remaining" description = ', '.join(map(str, player_role.members)) await ctx.send("", embed=gen_embed(title, description))
async def simon(ctx): """ Get the current Simon """ simon_role = get(ctx.guild.roles, name=get_role("Simon")) if len(simon_role.members) == 0: await ctx.send("", embed=gen_embed("Current Simon", f"There are currently no users with the {simon_role.mention} role.")) else: await ctx.send("", embed=gen_embed("Current Simon", ", ".join(map(str, simon_role.members))))
async def winner(self, ctx, winner: Member): """ Sets the last winner """ winner_role = get(ctx.guild.roles, name=get_role("Winner")) for member in winner_role.members: await member.remove_roles(winner_role) await winner.add_roles(winner_role) await ctx.send("", embed=gen_embed(f"Set {winner} as {winner_role.name}."))
def adduser(): form = UserForm() if form.validate_on_submit(): fn = request.form['first_name'] ln = request.form['last_name'] new_user = User(id=request.form['UID'],name=fn + ' ' + ln,first_name=fn, last_name=ln,url=request.form['URL'], in_out=False, active=True) for role in Role.query.all(): if request.form.get(role.name): new_user.roles.append(get_role(role.name)) db.session.add(new_user) db.session.commit() return redirect(url_for('admin.userlist')) flash_errors(form) return render_template('admin/adduser.html', title=app.config['BASE_HTML_TITLE'], edit_mode=False, add_mode=True, roles=Role.query.all(), form=form)
def edit_user(): arg = request.args.get('dict') dic = json.loads(arg)[0] arg1 = request.args.get('roles') roles_checked = json.loads(arg1)[0] user = User.query.get(dic['uid']) user.name = dic['name'] user.url = dic['URL'] user.active = dic['active'] for role in Role.query.all(): # Role is checked if roles_checked[role.name]: if role not in user.roles: user.roles.append(get_role(role.name)) # Role is unchecked else: if role in user.roles: user.roles.remove(role) db.session.commit() return jsonify()
from asyncio import sleep from configparser import ConfigParser from os import getenv from simon import Simon from helpers import gen_embed, get_role config = ConfigParser() config.read("config.ini") bot = Bot("$") @bot.command() @has_any_role(get_role("Admin"), get_role("Owner")) async def setsimon(ctx, user: Member = None): """ Set a user as Simon """ if user == None: user = ctx.author simon_role = get(ctx.guild.roles, name=get_role("Simon")) player_role = get(ctx.guild.roles, name=get_role("Player")) loser_role = get(ctx.guild.roles, name=get_role("Loser")) giveaway_role = get(ctx.guild.roles, name=get_role("Giveaways")) await user.add_roles(simon_role, giveaway_role) await user.remove_roles(player_role, loser_role)
class Simon(Cog): def __init__(self, bot): self.bot = bot @command(aliases=["e"]) @has_any_role(get_role("Simon"), get_role("Admin"), get_role("Owner")) async def elim(self, ctx, *users: Member): """ Eliminate users """ player_role = get(ctx.guild.roles, name=get_role("Player")) loser_role = get(ctx.guild.roles, name=get_role("Loser")) for user in users: await user.remove_roles(player_role) await user.add_roles(loser_role) await ctx.send("", embed=gen_embed("Eliminated user(s).")) @command(aliases=["r"]) @has_any_role(get_role("Simon"), get_role("Admin"), get_role("Owner")) async def revive(self, ctx, *users: Member): """ Revive users """ player_role = get(ctx.guild.roles, name=get_role("Player")) loser_role = get(ctx.guild.roles, name=get_role("Loser")) for user in users: await user.remove_roles(loser_role) await user.add_roles(player_role) await ctx.send("", embed=gen_embed("Revived user(s).")) @command() @has_any_role(get_role("Simon"), get_role("Admin"), get_role("Owner")) async def gameover(self, ctx): """ Remove all Simon Says roles """ simon_role = get(ctx.guild.roles, name=get_role("Simon")) player_role = get(ctx.guild.roles, name=get_role("Player")) loser_role = get(ctx.guild.roles, name=get_role("Loser")) giveaway_role = get(ctx.guild.roles, name=get_role("Giveaways")) total_members = 0 lines = [] for member in simon_role.members: await member.remove_roles(simon_role, giveaway_role) total_members += 1 lines.append( f"Removed {simon_role.mention} and {giveaway_role.mention} roles from {member}." ) for role in [player_role, loser_role]: members = 0 for member in role.members: await member.remove_roles(role) members += 1 if members != 0: total_members += members lines.append( f"Removed the {role.mention} role from {members} member(s)." ) if total_members == 0: lines.append(f"There were no roles to remove.") await ctx.send("", embed=gen_embed("Game Over", "\n".join(lines))) @command(aliases=["w"]) @has_any_role(get_role("Simon"), get_role("Admin"), get_role("Owner")) async def winner(self, ctx, winner: Member): """ Sets the last winner """ winner_role = get(ctx.guild.roles, name=get_role("Winner")) for member in winner_role.members: await member.remove_roles(winner_role) await winner.add_roles(winner_role) await ctx.send("", embed=gen_embed(f"Set {winner} as {winner_role.name}."))