2018-08-10 06:13:56 +02:00
import aiohttp
2017-05-20 09:50:29 +02:00
class Commands ( ) :
2018-08-10 06:13:56 +02:00
def __init__ ( self , client , config ) :
2017-05-20 09:50:29 +02:00
self . client = client
2018-08-10 06:13:56 +02:00
self . config = config
2017-05-27 04:00:50 +02:00
2017-05-20 09:50:29 +02:00
async def ban ( self , message ) :
2018-03-24 09:19:46 +01:00
if not message . author . guild_permissions . ban_members :
await message . channel . send ( message . author . mention + " I ' m sorry, but you do not have permissions to ban guest members. " )
2017-05-27 04:24:04 +02:00
return
2017-05-27 04:00:50 +02:00
content = message . content . strip ( )
if len ( content . split ( ) ) == 2 :
2018-03-24 09:19:46 +01:00
await message . channel . send ( message . author . mention + " Please provide a username-query (or optionally a discriminator) to ban a guest user. \n Example: `ban Titan#0001` " )
2017-05-27 04:00:50 +02:00
return
content = content . split ( )
username = content [ 2 ] [ : content [ 2 ] . find ( " # " ) ] if " # " in content [ 2 ] else content [ 2 ]
discriminator = int ( content [ 2 ] [ content [ 2 ] . find ( " # " ) + 1 : ] ) if " # " in content [ 2 ] else None
2018-08-10 06:13:56 +02:00
headers = { " Authorization " : self . config [ " bot-token " ] }
payload = {
" guild_id " : message . guild . id ,
" placer_id " : message . author . id ,
" username " : username
}
if discriminator :
payload [ " discriminator " ] = discriminator
url = self . config [ " titan-web-url " ] + " api/bot/ban "
async with aiohttp . ClientSession ( ) as aioclient :
async with aioclient . post ( url , json = payload , headers = headers ) as resp :
j = await resp . json ( )
if " error " in j :
await message . channel . send ( message . author . mention + " Ban error! " + j [ " error " ] )
return
if " success " in j :
await message . channel . send ( message . author . mention + " " + j [ " success " ] )
return
await message . channel . send ( " Unhandled webservice error in banning guest user! " )
2017-05-27 04:00:50 +02:00
async def kick ( self , message ) :
2018-03-24 09:19:46 +01:00
if not message . author . guild_permissions . kick_members :
await message . channel . send ( message . author . mention + " I ' m sorry, but you do not have permissions to kick guest members. " )
2017-05-27 04:24:04 +02:00
return
2017-05-27 04:00:50 +02:00
content = message . content . strip ( )
if len ( content . split ( ) ) == 2 :
2018-03-24 09:19:46 +01:00
await message . channel . send ( message . author . mention + " Please provide a username-query (or optionally a discriminator) to kick a guest user. \n Example: `kick Titan#0001` " )
2017-05-27 04:00:50 +02:00
return
content = content . split ( )
username = content [ 2 ] [ : content [ 2 ] . find ( " # " ) ] if " # " in content [ 2 ] else content [ 2 ]
discriminator = int ( content [ 2 ] [ content [ 2 ] . find ( " # " ) + 1 : ] ) if " # " in content [ 2 ] else None
2018-08-10 06:13:56 +02:00
headers = { " Authorization " : self . config [ " bot-token " ] }
payload = {
" guild_id " : message . guild . id ,
" username " : username
}
if discriminator :
payload [ " discriminator " ] = discriminator
url = self . config [ " titan-web-url " ] + " api/bot/revoke "
async with aiohttp . ClientSession ( ) as aioclient :
async with aioclient . post ( url , json = payload , headers = headers ) as resp :
j = await resp . json ( )
if " error " in j :
await message . channel . send ( message . author . mention + " Kick error! " + j [ " error " ] )
return
if " success " in j :
await message . channel . send ( message . author . mention + " " + j [ " success " ] )
return
await message . channel . send ( " Unhandled webservice error in kicking guest user! " )
2018-01-09 23:58:41 +01:00
async def invite ( self , message ) :
2018-03-24 09:19:46 +01:00
await message . channel . send ( " You can invite Titan to your server by visiting this link: https://discordapp.com/oauth2/authorize?&client_id=299403260031139840&scope=bot&permissions=641195117 " )
2018-01-10 02:07:28 +01:00
async def server ( self , message ) :
2018-03-24 09:19:46 +01:00
await message . channel . send ( " Join the Titan Embeds Discord server! https://discord.gg/pFDDtcN " )
2018-01-09 23:58:41 +01:00
2018-03-24 18:04:09 +01:00
async def shard ( self , message ) :
2018-03-24 18:21:13 +01:00
await message . channel . send ( " This instance of Titan Embeds Discord Bot is running on shard ** {} **. There are ** {} ** shards in total. " . format ( message . guild . shard_id , self . client . shard_count ) )