66
77from helpfunctions .utils import Utils
88from helpfunctions .xpfunk import Xpfunk
9- from datahandler .jsonhandle import Jsonhandle
9+ from datahandler .configHandle import ConfigHandle
10+ from datahandler .userHandle import UserHandle
1011from datahandler .textban import Textban
1112
1213
@@ -17,8 +18,9 @@ class Commandlistener(commands.Cog):
1718
1819 def __init__ (self , bot ):
1920 self .bot = bot
20- self .jh = Jsonhandle ()
21- self .utils = Utils (bot , jh = self .jh )
21+ self .ch = ConfigHandle ()
22+ self .uh = UserHandle ()
23+ self .utils = Utils (bot , ch = self .ch , uh = self .uh )
2224 self .xpf = Xpfunk ()
2325
2426 @commands .Cog .listener ()
@@ -48,13 +50,13 @@ async def on_ready(self):
4850 # Sends message to mods, when bot is online
4951 print ("Now Online" )
5052 await self .utils .sendModsMessage (
51- "Bot is now online.\n Version:\t DiscordBot DataBot v2.3.0 "
53+ "Bot is now online.\n Version:\t DiscordBot DataBot v2.3.1 "
5254 )
5355 # Sets the bot's presence to "Online" or "Do not Disturb" to indicate if it's logging or not.
54- if self .jh .getFromConfig ("log" ) == "True" :
55- await self .bot .change_presence (status = discord .Status .online , activity = discord .Game (str (self .jh .getFromConfig ("command_prefix" )) + "help" ))
56+ if self .ch .getFromConfig ("log" ) == "True" :
57+ await self .bot .change_presence (status = discord .Status .online , activity = discord .Game (str (self .ch .getFromConfig ("command_prefix" )) + "help" ))
5658 else :
57- await self .bot .change_presence (status = discord .Status .dnd , activity = discord .Game (str (self .jh .getFromConfig ("command_prefix" )) + "help" ))
59+ await self .bot .change_presence (status = discord .Status .dnd , activity = discord .Game (str (self .ch .getFromConfig ("command_prefix" )) + "help" ))
5860
5961 # When a member joins a guild
6062 @commands .Cog .listener ()
@@ -64,14 +66,14 @@ async def on_member_join(self, member):
6466
6567 Creates a welcome message in the log channel
6668 """
67- channel = self .bot .get_channel (int (self .jh .getFromConfig ("logchannel" )))
68- guild = self .bot .get_guild (int (self .jh .getFromConfig ("guild" )))
69+ channel = self .bot .get_channel (int (self .ch .getFromConfig ("logchannel" )))
70+ guild = self .bot .get_guild (int (self .ch .getFromConfig ("guild" )))
6971 await channel .send (f"Hey **{ member .mention } **, welcome to { guild } " )
7072
7173 """
7274 @commands.Cog.listener()
7375 async def on_disconnect(self):
74- owner = self.bot.get_user(int(self.jh .getFromConfig("owner")))
76+ owner = self.bot.get_user(int(self.ch .getFromConfig("owner")))
7577 await self.utils.sendOwnerMessage("Bot is offline.")
7678 """
7779
@@ -83,16 +85,16 @@ async def on_member_remove(self, member):
8385
8486 Sends a goodbye message in the log channel
8587 """
86- channel = self .bot .get_channel (int (self .jh .getFromConfig ("logchannel" )))
87- guild = self .bot .get_guild (int (self .jh .getFromConfig ("guild" )))
88+ channel = self .bot .get_channel (int (self .ch .getFromConfig ("logchannel" )))
89+ guild = self .bot .get_guild (int (self .ch .getFromConfig ("guild" )))
8890 await channel .send (
8991 f"**{ member .name } ** has left { guild } . Press F to pay respect."
9092 )
9193 """
9294 #Hash user data
93- voice = jh .getUserVoice(member.id)
94- text = jh .getUserText(member.id)
95- textCount = jh .getUserTextCount(member.id)
95+ voice = uh .getUserVoice(member.id)
96+ text = uh .getUserText(member.id)
97+ textCount = uh .getUserTextCount(member.id)
9698 [hash, code] = self.utils.hashData(voice, text, textCount, member.id)
9799 #Send user data
98100 embed = discord.Embed(title=f"{member.nick} ({member.name})", color=12008408)
@@ -105,7 +107,7 @@ async def on_member_remove(self, member):
105107 user = await bot.fetch_user(member.id)
106108 await user.send(content=f"**User related data from {server.name}**", embed=embed)
107109 await user.send(f"If you would like to join the Server again type this command to gain back your data **after** rejoining the server.\n ```+reclaim {voice} {text} {textCount} {code} {hash}```\n https://discord.gg/3Fk4gnQ2Jz")
108- jh .removeUserFromData(member.id)
110+ uh .removeUserFromData(member.id)
109111 """
110112
111113 # When a reacting is added
@@ -205,14 +207,14 @@ async def on_raw_reaction_add(self, payload):
205207 else :
206208 # Give reaction XP
207209 channel = self .bot .get_channel (payload .channel_id )
208- if self .jh .isInWhitelist (payload .channel_id ):
210+ if self .ch .isInWhitelist (payload .channel_id ):
209211 message = await channel .fetch_message (payload .message_id )
210212 if (
211213 not (message .author .bot or payload .member .bot )
212- and self .jh .getFromConfig ("log" ) == "True"
214+ and self .ch .getFromConfig ("log" ) == "True"
213215 ):
214- self .jh .addReactionXP (payload .user_id , self .xpf .randomRange (1 , 5 ))
215- self .jh .saveData ()
216+ self .uh .addReactionXP (payload .user_id , self .xpf .randomRange (1 , 5 ))
217+ self .uh .saveData ()
216218
217219 # When a user changes his voice state
218220 @commands .Cog .listener ()
@@ -265,14 +267,14 @@ async def on_voice_state_update(self, member, before, after):
265267 )
266268
267269 # Removes channel from blacklist if necessary
268- self .jh .removeFromBalcklist (lastChannel .id )
270+ self .ch .removeFromBalcklist (lastChannel .id )
269271
270272 await lastChannel .delete ()
271273
272274 # User left channel, which is not the first channel. So it will be deleted
273275 else :
274276 # Removes channel from blacklist if necessary
275- self .jh .removeFromBalcklist (before .channel .id )
277+ self .ch .removeFromBalcklist (before .channel .id )
276278 await before .channel .delete ()
277279
278280 """
@@ -332,8 +334,8 @@ async def on_voice_state_update(self, member, before, after):
332334 # Creates channel and gets it
333335 newChannel = await channelWithNumberBefore .clone (name = newChannelName )
334336
335- if self .jh .isInBlacklist (after .channel .id ):
336- self .jh .writeToBalcklist (newChannel .id )
337+ if self .ch .isInBlacklist (after .channel .id ):
338+ self .ch .writeToBalcklist (newChannel .id )
337339
338340 # Move channel after channelWithNumberBefore
339341 await newChannel .move (after = channelWithNumberBefore )
@@ -359,37 +361,37 @@ async def on_message(self, message):
359361 a = "" + message .content
360362
361363 # Stops user from writting in levelchannel none command messages
362- if str (message .channel .id ) == str (self .jh .getFromConfig ("levelchannel" )) and a [
364+ if str (message .channel .id ) == str (self .ch .getFromConfig ("levelchannel" )) and a [
363365 0
364- ] != self .jh .getFromConfig ("command_prefix" ):
366+ ] != self .ch .getFromConfig ("command_prefix" ):
365367 await message .delete ()
366368 return
367369
368370 # Checks if message contains a picture
369- if len (message .attachments ) > 0 and self .jh .getFromConfig ("log" ) == "True" :
371+ if len (message .attachments ) > 0 and self .ch .getFromConfig ("log" ) == "True" :
370372 attachments = message .attachments
371373 userID = message .author .id
372374 for attachment in attachments :
373375 name = attachment .filename
374376 if name .endswith ("jpg" ) or name .endswith ("png" ):
375377 # Gives XP when picture is in message
376- self .jh .addTextXP (userID , self .xpf .randomRange (20 , 40 ))
377- self .jh .saveData ()
378+ self .uh .addTextXP (userID , self .xpf .randomRange (20 , 40 ))
379+ self .uh .saveData ()
378380 return
379381
380382 # When Message is a String
381383 if (
382384 a != ""
383- and a [0 ] != self .jh .getFromConfig ("command_prefix" )
384- and self .jh .getFromConfig ("log" ) == "True"
385+ and a [0 ] != self .ch .getFromConfig ("command_prefix" )
386+ and self .ch .getFromConfig ("log" ) == "True"
385387 ):
386388 # Give XP when message is not a command
387- if self .jh .isInWhitelist (message .channel .id ):
388- self .jh .addTextXP (message .author .id , self .xpf .textXP (a ))
389- self .jh .saveData ()
389+ if self .ch .isInWhitelist (message .channel .id ):
390+ self .uh .addTextXP (message .author .id , self .xpf .textXP (a ))
391+ self .uh .saveData ()
390392
391393 # Sends BotOwner commands, which are triggering the bot
392- if len (a ) > 0 and a [0 ] == self .jh .getFromConfig ("command_prefix" ):
394+ if len (a ) > 0 and a [0 ] == self .ch .getFromConfig ("command_prefix" ):
393395 channelName = "DM"
394396 try :
395397 channelName = message .channel .name
0 commit comments