mirror of
				https://github.com/TitanEmbeds/Titan.git
				synced 2025-11-03 23:37:09 +01:00 
			
		
		
		
	Initial command structure for bot
This commit is contained in:
		@@ -1,5 +1,6 @@
 | 
				
			|||||||
from config import config
 | 
					from config import config
 | 
				
			||||||
from titanembeds.database import DatabaseInterface
 | 
					from titanembeds.database import DatabaseInterface
 | 
				
			||||||
 | 
					from titanembeds.commands import Commands
 | 
				
			||||||
import discord
 | 
					import discord
 | 
				
			||||||
import aiohttp
 | 
					import aiohttp
 | 
				
			||||||
import asyncio
 | 
					import asyncio
 | 
				
			||||||
@@ -15,6 +16,7 @@ class Titan(discord.Client):
 | 
				
			|||||||
        self.aiosession = aiohttp.ClientSession(loop=self.loop)
 | 
					        self.aiosession = aiohttp.ClientSession(loop=self.loop)
 | 
				
			||||||
        self.http.user_agent += ' TitanEmbeds-Bot'
 | 
					        self.http.user_agent += ' TitanEmbeds-Bot'
 | 
				
			||||||
        self.database = DatabaseInterface(self)
 | 
					        self.database = DatabaseInterface(self)
 | 
				
			||||||
 | 
					        self.command = Commands(self, self.database)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def _cleanup(self):
 | 
					    def _cleanup(self):
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
@@ -82,7 +84,15 @@ class Titan(discord.Client):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    async def on_message(self, message):
 | 
					    async def on_message(self, message):
 | 
				
			||||||
        await self.database.push_message(message)
 | 
					        await self.database.push_message(message)
 | 
				
			||||||
        # TODO: Will add command handler + ban/kick command
 | 
					        
 | 
				
			||||||
 | 
					        msg_arr = message.content.split() # split the message
 | 
				
			||||||
 | 
					        if len(message.content.split()) > 1 and message.server: #making sure there is actually stuff in the message and have arguments and check if it is sent in server (not PM)
 | 
				
			||||||
 | 
					            if msg_arr[0] == "<@{}>".format(self.user.id): #make sure it is mention
 | 
				
			||||||
 | 
					                msg_cmd = msg_arr[1].lower() # get command
 | 
				
			||||||
 | 
					                cmd = getattr(self.command, msg_cmd, None) #check if cmd exist, if not its none
 | 
				
			||||||
 | 
					                if cmd: # if cmd is not none...
 | 
				
			||||||
 | 
					                    await self.send_typing(message.channel) #this looks nice
 | 
				
			||||||
 | 
					                    await getattr(self.command, msg_cmd)(message) #actually run cmd, passing in msg obj
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async def on_message_edit(self, message_before, message_after):
 | 
					    async def on_message_edit(self, message_before, message_after):
 | 
				
			||||||
        await self.database.update_message(message_after)
 | 
					        await self.database.update_message(message_after)
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										8
									
								
								discordbot/titanembeds/commands.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								discordbot/titanembeds/commands.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
				
			|||||||
 | 
					class Commands():
 | 
				
			||||||
 | 
					    def __init__(self, client, database):
 | 
				
			||||||
 | 
					        self.client = client
 | 
				
			||||||
 | 
					        self.database = database
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    async def ban(self, message):
 | 
				
			||||||
 | 
					        pass
 | 
				
			||||||
 | 
					        #await self.client.send_message(message.channel, "test test!")
 | 
				
			||||||
@@ -293,3 +293,9 @@ class DatabaseInterface(object):
 | 
				
			|||||||
                        db.session.add(dbusr)
 | 
					                        db.session.add(dbusr)
 | 
				
			||||||
                if changed:
 | 
					                if changed:
 | 
				
			||||||
                    session.commit()
 | 
					                    session.commit()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    async def ban_unauth_user_by_query(self, query):
 | 
				
			||||||
 | 
					        async with threadpool():
 | 
				
			||||||
 | 
					            with self.get_session() as session:
 | 
				
			||||||
 | 
					                pass
 | 
				
			||||||
 | 
					                #dbusr = session.query()
 | 
				
			||||||
		Reference in New Issue
	
	Block a user