client=commands.Bot(command_prefix=p,description=f'Geas Server Bot v {os.getenv("BOT_VERSION")}. This is a bot to facilitate setting up game channels on the Geas server. The prefix for the bot is {p}. You can interact with and manipulate game channels that have been created with this bot by @-mentioning the relevant role associated with the game.',intents=intents)
raisecommands.CommandError('Error: you must invoke this command in a text channel corresponding to the game you are attempting to delete.')
raisecommands.CommandError(f'Error: you must invoke this command in the text channel of your game.')
# setupGame command: <when>, <@GM> <capacity>, <Name of game>
@client.command(name='setupgame',aliases=['setup','gamesetup','creategame','gamecreate','create'],description='Use this command to set up the roles and channels for a new game. The syntax is `setup {wed|sunaft|suneve|oneshot|other} {@GM Name} {Capacity}{Name of game}`')
awaitc.create_voice_channel(name=f'voice: {gameTitle}',topic=f'Default voice channel for {gameTitle}')
t=awaitc.create_text_channel(name=f'text: {gameTitle}',topic=f'Default text channel for {gameTitle}')
awaitctx.channel.send(f'Game {r.mention} has been created with GM {gmMember.mention} and space for {cap} players.')
awaitt.send(f'Hello, {gmMember.mention}! Your game channels for {gameTitle} have now been set up.\nYou can also ping your players or interact with the bot commands by mentioning the {r.mention} role.')
else:
awaitc.edit(overwrites=permissions)
tPos=len(ctx.guild.channels)
tFirst=None
vExists=False
fortinc.text_channels:
ift.position<=tPos:
tFirst=t
tPos=t.position
awaitt.edit(sync_permissions=True)
forvinc.voice_channels:
awaitv.edit(sync_permissions=True)
vExists=True
awaitctx.channel.send(f'The category for game {r.mention} has been reset for GM {gmMember.mention} with space for {cap} players.')
iftFirst==None:
tFirst=awaitc.create_text_channel(name=f'text: {gameTitle}',topic=f'Default text channel for {gameTitle}')
ifnotvExists:
awaitc.create_voice_channel(name=f'voice: {gameTitle}',topic=f'Default voice channel for {gameTitle}')
awaittFirst.send(f'Hello, {gmMember.mention}! Your game channels for {gameTitle} have now been set up.\nYou can also ping your players or interact with the bot commands by mentioning the {r.mention} role.')
awaitctx.channel.send('The number of players in the game must be an integer.')
raiseerror
# defineBotrole command
@client.command(name='definebotrole',aliases=['setbotrole','botrole','botroleset','botroledefine','br'],description='This is a set-up command to define which role is the botrole that the dice bot use. The syntax is `botrole {@Role}`')
@commands.has_permissions(administrator=True)
asyncdefdefineBotrole(ctx,arg):
ifnotarg.startswith('<@&'):
raisecommands.CommandError('Invalid argument. The argument must @ a role.')
dbName=str(ctx.guild.id)
colName='settings'
r=ctx.guild.get_role(int(arg[3:-1]))
ifdbNamenotinstate:
state[dbName]={}
if'settings'notinstate[dbName]:
state[dbName]['settings']={}
ret=state[dbName]['settings']
ret['_id']=0
if'botrole'notinret:
awaitctx.channel.send(f'Bot role for server {ctx.guild.name} not set. Setting {r.mention} to bot role now.')
else:
awaitctx.channel.send(f'Bot role for server {ctx.guild.name} has already been set to {ctx.guild.get_role(ret["botrole"]).mention}. Updating to {r.mention}.')
@client.command(name='deletegame',aliases=['delete','del','removegame','delgame','gamedel','gamedelete'],description='Use this command to delete the role and associated channels for a game. The syntax is `delete {@Game Role}`. **It must be called in a text channel inside the relevant game.**')
@commands.has_permissions(administrator=True)
@commands.check(in_game_channel)
asyncdefdeleteGame(ctx,arg):
ifnotarg.startswith('<@&'):
raisecommands.CommandError('Invalid argument. The argument must @ a role.')
r=ctx.guild.get_role(int(arg[3:-1]))
cat=dbLookupRole(ctx.guild,r)
dbName=str(ctx.guild.id)
db=dbClient[dbName]
awaitctx.channel.trigger_typing()
try:
colName=dbFindTimeslot(ctx.guild,r)
except:
raisecommands.CommandError(f'Invalid argument. {r.mention} role is not a valid game role.')
@client.command(name='reset',aliases=['deleteall','delall','cleargames','clear'],description='This deletes all games in a particular time slot category. This is a very powerful command. Be careful when you use it. The syntax is `reset {wed|sunaft|suneve|oneshot|other|all}`')
awaitctx.channel.send(f'All games for {colName} have been deleted.')
# Migrate Guild from Old Server Settings to New Settings
@client.command(name='migrate',aliases=['migrategames','migratedata'],description='A set-up command to migrate games from the old server settings to the new server settings using the database for the first time.')