Skip to content

Commit

Permalink
Merge pull request #21 from PantomInach/testing
Browse files Browse the repository at this point in the history
Testing from refactor to main
  • Loading branch information
PantomInach authored Aug 1, 2021
2 parents c918eba + 2be5010 commit 4311a22
Show file tree
Hide file tree
Showing 16 changed files with 724 additions and 662 deletions.
1 change: 1 addition & 0 deletions bin/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"levelchannel":"",
"spamchannel":"",
"infochannel":"",
"loginchannel":"",
"owner": "",
"textCooldown": "",
"privilege": {
Expand Down
8 changes: 0 additions & 8 deletions bin/test.py

This file was deleted.

53 changes: 22 additions & 31 deletions bot/commandmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ def __init__(self, bot, helpf, jh, xpf):
async def addblacklist(self, ctx, channelID):
message = "Your are not permitted to use this command. You need Mod privileges"
if int(self.jh.getPrivilegeLevel(ctx.author.id)) > 0:
server = self.bot.get_guild(self.jh.getFromConfig("server"))
channels = await self.helpf.channelList(self.jh.getFromConfig("server"))
guilde = self.bot.get_guild(self.jh.getFromConfig("server"))
channels = self.helpf.getVoiceChannelsFrom(self.jh.getFromConfig("server"))
#Test if channel is in Server
if str(channelID) in channels:
if str(channelID) in [str(channel.id) for channel in channels]:
#Try to write in Blacklist
if self.jh.writeToBalcklist(channelID):
channelName = str(self.bot.get_channel(int(channelID)))
message = f"Added {channelName} with id {channelID} to Blacklist. This Voice channel will not be logged."
else:
message = "Channel is already in Blacklist."
else:
message = f"Channel is not in the server {str(server)}"
message = f"Channel is not in the server {str(guilde)}"
author = ctx.author
await self.helpf.log(f"{message} from user {author}",2)
await ctx.send(message)
Expand All @@ -55,18 +55,18 @@ async def removeblacklist(self, ctx, channelID):
async def addtextwhitelist(self, ctx, channelID):
message = "Your are not permitted to use this command. You need Mod privileges"
if int(self.jh.getPrivilegeLevel(ctx.author.id)) > 0:
server = self.bot.get_guild(self.jh.getFromConfig("server"))
channels = await self.helpf.channelList(self.jh.getFromConfig("server"))
guilde = self.bot.get_guild(self.jh.getFromConfig("server"))
channels = self.helpf.getTextChannelsFrom(self.jh.getFromConfig("server"))
#Test if channel is in Server
if str(channelID) in channels:
if str(channelID) in [str(channel.id) for channel in channels]:
#Try to write in whitelist
if self.jh.writeToWhitelist(channelID):
channelName = str(self.bot.get_channel(int(channelID)))
message = f"Added {channelName} with id {channelID} to Whitelist. This Text channel will be logged."
else:
message = "Channel is already in Whitelist."
else:
message = f"Channel is not in the server {str(server)}"
message = f"Channel is not in the server {str(guilde)}"
author = ctx.author
await self.helpf.log(f"{message} from user {author}",2)
await ctx.send(message)
Expand All @@ -86,23 +86,20 @@ async def removetextwhitelist(self, ctx, channelID):
await self.helpf.log(f"{message} from user {author}",2)
await ctx.send(message)

#TODO: Does not creat new user. Use somehow jh.addNewDataEntry(userID)
@commands.command(name='getuserdata', brief='Gives VoiceXP, TextXP and writen messages back.', description='You need privilege level 1 to use this command. Returns UserName, UserID, VoiceXP, TextXP and writen messages back. As an input you need the user id, which you can get by rigth clicking on the user.')
async def getUserData(self, ctx, userID):
message = "Your are not permitted to use this command. You need Mod privileges"
if int(self.jh.getPrivilegeLevel(ctx.author.id)) > 0:
if self.jh.isInData(userID):
userData = self.jh.data[str(userID)]
voice = userData["Voice"]
text = userData["Text"]
textCount = userData["TextCount"]
voice = self.jh.getUserVoice(userID)
text = self.jh.getUserText(userID)
textCount = self.getUserTextCount(userID)
message = f"User: {str(self.bot.get_user(int(userID)))} VoiceXP: {voice} TextXP: {text} TextCount: {textCount}"
else:
user = self.bot.get_user(int(userID))
message = f"User was not in data. Created user: {user.mention}"
await ctx.send(message)

#TODO: Does not creat new user. Use somehow jh.addNewDataEntry(userID)
@commands.command(name='setvoicexp',brief='Sets the voiceXP of a user.', description='You need privilege level 1 to use this command. Sets the voiceXP to the given amount. As an input you need the userID, which you can get by rigth clicking on the user, and the value of the XP.')
async def setVoiceXP(self, ctx, userID, amount):
message = "Your are not permitted to use this command. You need Mod privileges"
Expand All @@ -111,13 +108,11 @@ async def setVoiceXP(self, ctx, userID, amount):
if not self.jh.isInData(userID):
message = f"User was not in data. Created user: {self.bot.get_user(int(userID))}\n"
self.jh.addNewDataEntry(userID)
self.jh.data[str(userID)]["Voice"] = str(amount)
self.jh.saveData()
message += f"Set user {str(self.bot.get_user(int(userID)))} voiceXP to{amount}."
self.jh.setUserVoice(userID, amount)
message += f"Set user {str(self.bot.get_user(int(userID)))} voiceXP to {amount}."
await self.helpf.log(f"User {ctx.author} set user {str(self.bot.get_user(int(userID)))} voiceXP to {amount}.",2)
await ctx.send(message)

#TODO: Does not creat new user. Use somehow jh.addNewDataEntry(userID)
@commands.command(name='settextxp',brief='Sets the textXP of a user.', description='You need privilege level 1 to use this command. Sets the TextXP to the given amount. As an input you need the userID, which you can get by rigth clicking on the user, and the value of the XP.')
async def setTextXP(self, ctx, userID, amount):
message = "Your are not permitted to use this command. You need Mod privileges"
Expand All @@ -126,13 +121,11 @@ async def setTextXP(self, ctx, userID, amount):
if not self.jh.isInData(userID):
message = f"User was not in data. Created user: {self.bot.get_user(int(userID))}\n"
self.jh.addNewDataEntry(userID)
self.jh.data[str(userID)]["Text"] = str(amount)
self.jh.saveData()
self.jh.setUserText(userID, amount)
message += f"Set user {str(self.bot.get_user(int(userID)))} textXP to {amount}."
await self.helpf.log(f"User {ctx.author} set user {str(self.bot.get_user(int(userID)))} textXP to {amount}.",2)
await ctx.send(message)

#TODO: Does not creat new user. Use somehow jh.addNewDataEntry(userID)
@commands.command(name='settextcount',brief='Sets the textCount of a user.', description='You need privilege level 1 to use this command. Sets the TextCount to the given amount. As an input you need the userID, which you can get by rigth clicking on the user, and the value of the XP.')
async def setTextCount(self, ctx, userID, amount):
message = "Your are not permitted to use this command. You need Mod privileges"
Expand All @@ -141,8 +134,7 @@ async def setTextCount(self, ctx, userID, amount):
if not self.jh.isInData(userID):
message = f"User was not in data. Created user: {self.bot.get_user(int(userID))}\n"
self.jh.addNewDataEntry(userID)
self.jh.data[str(userID)]["TextCount"] = str(amount)
self.jh.saveData()
self.jh.setUserTextCount(userID, amount)
message += f"Set user {str(self.bot.get_user(int(userID)))} TextCount to {amount}."
await self.helpf.log(f"User {ctx.author} set user {str(self.bot.get_user(int(userID)))} textCount to {amount}.",2)
await ctx.send(message)
Expand All @@ -151,16 +143,15 @@ async def setTextCount(self, ctx, userID, amount):
async def printData(self,ctx):
message = "Your are not permitted to use this command. You need Mod privileges"
if int(self.jh.getPrivilegeLevel(ctx.author.id)) > 0:
server = str(self.bot.get_guild(int(self.jh.getFromConfig("server"))))
message = f"Printing data of server {server}:\n"
guilde = str(self.bot.get_guild(int(self.jh.getFromConfig("server"))))
message = f"Printing data of server {guilde}:\n"
# Sorts user by there usernames
sortedData = sorted(self.jh.data, key = lambda id: str(self.bot.get_user(int(id)).name).lower() if self.bot.get_user(int(id)) != None else "no user")
for userID in sortedData:
temp = self.jh.data[str(userID)]
level = temp["Level"]
voiceXP = temp["Voice"]
textXP = temp["Text"]
textCount = temp["TextCount"]
level = self.jh.getUserLevel(userID)
voiceXP = self.jh.getUserVoice(userID)
textXP = self.jh.getUserText(userID)
textCount = self.jh.getUserTextCount(userID)
user = self.bot.get_user(int(userID))
username = "No User"
#Handel not existing UserIDs
Expand All @@ -170,7 +161,7 @@ async def printData(self,ctx):
if len(message)+len(messageadd)>2000: #Get around 2000 char discord text limit
await ctx.send(message)
message = ""
message +=messageadd
message += messageadd
print(f"User {ctx.author} prints all data in {ctx.channel}.")
await ctx.send(message)

Expand Down
40 changes: 17 additions & 23 deletions bot/commandmodserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,19 @@ def __init__(self, bot, helpf, tban, counter, jh):
self.helpf = helpf

#Checks if cahnnel is a PM channel
def isPM(self, ctx):
def isDM(self, ctx):
return isinstance(ctx.channel, discord.channel.DMChannel)

#Checks if author has member, admin or mod rigths
async def hasRights(self, ctx):
server = self.bot.get_guild(int(self.jh.getFromConfig("server")))
userID = ctx.author.id
member = server.get_member(userID)
for roll in ["CEO", "COO"]:
if await self.helpf.hasRole(userID, roll):
return True
return False
def hasRights(self, ctx):
#Checks if author has member, admin or mod rigths
return self.helpf.hasOneRole(ctx.author.id, ["CEO", "COO"])

@commands.command(name='textban', brief='Textbans a user.', description='You need to be a \'Administrator\' or \'moderator\' to use this command. Can only be used in a private channel and \'log\'.\nAdds a user to the textban-list. The users text-messages will be deletet upon posting them. You can not change the ban time, only unban with \'+textunban\'.\nTo use this command you need the userID, which you can get be rigth-clicking on the person. Also a time is requiered. The time you input will be in seconds. Also a reason is requiered. The reason must be in \"\", otherwise the command wont work.')
async def textban(self, ctx, userID, time, reason):
pm = self.isPM(ctx)
dm = self.isDM(ctx)
logID = self.jh.getFromConfig("logchannel")
if pm or ctx.channel.id == int(logID):
if await self.hasRights(ctx):
if dm or ctx.channel.id == int(logID):
if self.hasRights(ctx):
if not self.tban.hasTextBan(userID):
bantime = 0
try:
Expand All @@ -44,11 +38,11 @@ async def textban(self, ctx, userID, time, reason):
bantime = -1
if bantime >= 0.1:
user = self.bot.get_user(int(userID))
server = self.bot.get_guild(int(self.jh.getFromConfig("server")))
member = server.get_member(int(userID))
guilde = self.bot.get_guild(int(self.jh.getFromConfig("server")))
member = guilde.get_member(int(userID))
if user != None:
logchannel = self.bot.get_channel(int(logID))
if not pm:
if not dm:
await ctx.message.delete()
await self.helpf.log(f"User {ctx.author.mention} textbaned {user.mention} for {time} h. Reason:\n{reason}",2)
await logchannel.send(f"{user.mention} was textbaned for {time} h.\n**Reason**: {reason}")
Expand All @@ -63,28 +57,28 @@ async def textban(self, ctx, userID, time, reason):
await ctx.send(content="ERROR: time is not valid.", delete_after=3600)
else:
await ctx.send(content="ERROR: User has already a textban.", delete_after=3600)
elif not pm:
elif not dm:
await ctx.message.delete()
if not pm:
if not dm:
await ctx.message.delete()


@commands.command(name='textunban', brief='Removes textban from user.', description='You need to be a \'Administrator\' or \'moderator\' to use this command. Can only be used in a private channel and \'log\'.\nThis command will remnove a person from the textban-list and the messages from the person wont be removed anymore.\nTo use this command you need the userID, which you can get be rigth-clicking on the person.')
async def textunban(self, ctx, userID):
pm = self.isPM(ctx)
dm = self.isDM(ctx)
logID = self.jh.getFromConfig("logchannel")
if pm or ctx.channel.id == logID:
if await self.hasRights(ctx) and not self.tban.hasTextBan(ctx.author.id):
if dm or ctx.channel.id == logID:
if self.hasRights(ctx) and not self.tban.hasTextBan(ctx.author.id):
if self.tban.removeTextBan(userID):
logchannel = self.bot.get_channel(int(logID))
user = self.bot.get_user(int(userID))
await self.helpf.log(f"User {ctx.author.mention} textunbaned {user.mention}",2)
await logchannel.send(f"User {ctx.author.mention} textunbaned {user.mention}")
else:
await ctx.send(content="ERROR: User has no textban.", delete_after=3600)
elif not pm:
elif not dm:
await ctx.message.delete()
if not pm:
if not dm:
await ctx.message.delete()

def setup(bot, helpf, tban, jh):
Expand Down
Loading

0 comments on commit 4311a22

Please sign in to comment.