Skip to content

Commit

Permalink
Merge pull request #23 from PantomInach/testing
Browse files Browse the repository at this point in the history
  • Loading branch information
PantomInach authored Aug 4, 2021
2 parents 4311a22 + d226ace commit 3567606
Show file tree
Hide file tree
Showing 12 changed files with 472 additions and 525 deletions.
26 changes: 10 additions & 16 deletions bin/config.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
{
"token": "Your Token",
"token": "Your token",
"command_prefix": "+",
"log": "False",
"logchannel": "",
"levelchannel":"",
"spamchannel":"",
"infochannel":"",
"loginchannel":"",
"levelchannel": "",
"owner": "",
"textCooldown": "",
"textCooldown": "75",
"privilege": {

"Your ID": "2",
"Lower rank ID": "1"
},
"server": "",
"guilde": "Your guilde ID",
"serverVoiceBlacklist": [
"0",
"0"
],
"serverTextWhitelist": [
"0",
"0"
],
"roles": [

],
"rolesXPNeed": [

]
"roles": [],
"rolesXPNeed": []
}
222 changes: 103 additions & 119 deletions bot/commandmod.py

Large diffs are not rendered by default.

111 changes: 50 additions & 61 deletions bot/commandmodserver.py
Original file line number Diff line number Diff line change
@@ -1,85 +1,74 @@
import discord
from discord.utils import get
from discord.ext import commands
from .textban import Textban
from .jsonhandel import Jsonhandel
from .helpfunc import Helpfunc
from .counter import Counter
from .decorators import *
import asyncio

def hasAnyRole(*items):
"""
commands.has_any_role() does not work in DM since a users can't have roles.
This on pulls the roles from the conffigured guilde and makes the same check as commands.has_any_role().
"""
def predicate(ctx):
return Commandmodserver.helpf.hasOneRole(ctx.author.id, [role for role in items])
return commands.check(predicate)

class Commandmodserver(commands.Cog, name='Server Mod Commands'):
"""docstring for Commandmodserver"""

helpf = None

def __init__(self, bot, helpf, tban, counter, jh):
super(Commandmodserver, self).__init__()
self.bot = bot
self.tban = tban
self.jh = jh
self.helpf = helpf

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

def hasRights(self, ctx):
#Checks if author has member, admin or mod rigths
return self.helpf.hasOneRole(ctx.author.id, ["CEO", "COO"])
Commandmodserver.helpf = helpf

@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.')
@isDM()
@hasAnyRole("CEO","COO")
async def textban(self, ctx, userID, time, reason):
dm = self.isDM(ctx)
logID = self.jh.getFromConfig("logchannel")
if dm or ctx.channel.id == int(logID):
if self.hasRights(ctx):
if not self.tban.hasTextBan(userID):
bantime = 0
try:
bantime = float(time)
except ValueError:
bantime = -1
if bantime >= 0.1:
user = self.bot.get_user(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 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}")
await user.send(content=f"You received a textban for {time} h.\n**Reason**: {reason}")
await self.helpf.sendServerModMessage(f"{member.nick} ({user.name}) was textbaned by {server.get_member(int(ctx.author.id)).nick} ({ctx.author.name}) for {time} h.\n**Reason**: {reason}")
await self.tban.addTextBan(userID, int(bantime*3600.0))
#Textban over
await user.send("Your Textban is over. Pay more attention to your behavior in the future.")
else:
await ctx.send(content="ERROR: User does not exist.", delete_after=3600)
else:
await ctx.send(content="ERROR: time is not valid.", delete_after=3600)
if not self.tban.hasTextBan(userID):
bantime = 0
try:
bantime = float(time)
except ValueError:
bantime = -1
if bantime >= 0.1:
user = self.bot.get_user(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(self.jh.getFromConfig("logchannel")))
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}")
await user.send(content=f"You received a textban for {time} h.\n**Reason**: {reason}")
await self.helpf.sendServerModMessage(f"{member.nick} ({user.name}) was textbaned by {guilde.get_member(int(ctx.author.id)).nick} ({ctx.author.name}) for {time} h.\n**Reason**: {reason}")
await self.tban.addTextBan(userID, int(bantime*3600.0))
#Textban over
await user.send("Your Textban is over. Pay more attention to your behavior in the future.")
else:
await ctx.send(content="ERROR: User has already a textban.", delete_after=3600)
elif not dm:
await ctx.message.delete()
if not dm:
await ctx.message.delete()
await ctx.send(content="ERROR: User does not exist.", delete_after=3600)
else:
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)


@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.')
@isDM()
@hasAnyRole("CEO","COO")
async def textunban(self, ctx, userID):
dm = self.isDM(ctx)
logID = self.jh.getFromConfig("logchannel")
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 dm:
await ctx.message.delete()
if not dm:
await ctx.message.delete()
if not self.tban.hasTextBan(ctx.author.id):
if self.tban.removeTextBan(userID):
logchannel = self.bot.get_channel(int(self.jh.getFromConfig("logchannel")))
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)

def setup(bot, helpf, tban, jh):
bot.add_cog(Commandpoll(bot, helpf, tban, jh))
168 changes: 68 additions & 100 deletions bot/commandowner.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import os
from discord.utils import get
from discord.ext import commands
from .jsonhandel import Jsonhandel
from .xpfunk import Xpfunk
from .helpfunc import Helpfunc
from .textban import Textban
from .decorators import *
import asyncio

class Commandowner(commands.Cog, name='Bot Owner Commands'):
Expand All @@ -20,143 +17,114 @@ def __init__(self, bot, helpf, tban, jh, xpf):
self.tban = tban

@commands.command(name='test', pass_context=True, brief='Testing command for programmer.', description='You need privilege level Owner to use this command. Only the programmer knows what happens here.')
@isBotOwner()
async def test(self, ctx):
if int(self.jh.getPrivilegeLevel(ctx.author.id)) == 2:
userID = ctx.author.id
server = self.bot.get_guild(int(self.jh.getFromConfig("server")))
member = server.get_member(int(userID))
self.jh.addNewDataEntry(userID)
#Create Embeded
avatar_url = ctx.author.avatar_url
level = self.jh.getUserLevel(userID)
voiceXP = self.jh.getUserVoice(userID)
textXP = self.jh.getUserText(userID)
textCount = self.jh.getUserTextCount(userID)
nextLevel = self.xpf.xpNeed(voiceXP,textXP)
embed = discord.Embed(title=f"{member.nick} ({ctx.author.name})", color=12008408)
embed.set_thumbnail(url=avatar_url)
embed.add_field(name="HOURS", value=f"{round(int(voiceXP)/30.0,1)}", inline=True)
embed.add_field(name="MESSAGES", value=f"{str(textCount)}", inline=True)
embed.add_field(name="EXPERIENCE", value=f"{str(int(voiceXP)+int(textXP))}/{nextLevel}",inline=True)
embed.add_field(name="LEVEL", value=f"{level}", inline=True)
#Send Embeded
await ctx.send(embed=embed, delete_after=86400)
await ctx.send("Geht")
await ctx.message.delete()

@commands.command(name="ping")
@isBotOwner()
async def ping(self, ctx):
if int(self.jh.getPrivilegeLevel(ctx.author.id)) == 2:
await ctx.send("pong")
await ctx.send("pong")

#Starts to log the users in voice channels
@commands.command(name='startlog', brief='Starts to log the users on the configured server.', description='You need privilege level 2 to use this command. Gets the connected users of the configured server und increments every minute their voice XP.')
@isBotOwner()
async def startlog(self, ctx):
if int(self.jh.getPrivilegeLevel(ctx.author.id)) == 2 and self.jh.getFromConfig("log")=="False":
if self.jh.getFromConfig("log") == "False":
self.jh.config["log"] = "True"
self.jh.saveConfig()
guildeID = int(self.jh.getFromConfig("server"))
guildeID = int(self.jh.getFromConfig("guilde"))
guildeName = str(self.bot.get_guild(guildeID))
await self.helpf.log(f"Start to log users from Server:\n\t{guildeName}",2)
while self.jh.getFromConfig("log"):
while self.jh.getFromConfig("log") == "True":
self.helpf.addMembersOnlineVoiceXp(guildeID)
await self.helpf.levelAkk()
await self.helpf.updateRoles()
self.jh.saveData()
await asyncio.sleep(120)
else:
if not int(self.jh.getPrivilegeLevel(ctx.author.id)) == 2:
await ctx.send(f"Your are not permitted to use this command. You need Owner privileges.")
else:
s = self.jh.getFromConfig("log")
await ctx.send(f"Bot is logging. Logging state: {s}")
await ctx.send(f"Bot is logging. Logging state: True")

@commands.command(name='stoplog', brief='Stops to log the users on configured server.', description='You need privilege level 2 to use this command. When the bot logs the connective users on the configured server, this command stops the logging process.')
@isBotOwner()
async def stoplog(self, ctx):
if int(self.jh.getPrivilegeLevel(ctx.author.id)) == 2 and self.jh.getFromConfig("log")=="True":
guildeID = int(self.jh.getFromConfig("server"))
if self.jh.getFromConfig("log")=="True":
guildeID = int(self.jh.getFromConfig("guilde"))
guildeName = str(self.bot.get_guild(guildeID))
self.jh.config["log"] = "False"
self.jh.saveConfig()
await self.helpf.log(f"Stopped to log users from Server:\n\t{guildeName}",2)
else:
await ctx.send(f"Your are not permitted to use this command. You need Owner privileges. Or logging is off.")
await ctx.send(f"Bot is NOT logging. Logging state: False")

@commands.command(name='stopbot', brief='Shuts down the bot.', description='You need privilege level 2 to use this command. This command shuts the bot down.')
@isBotOwner()
async def stopbot(self, ctx):
if int(self.jh.getPrivilegeLevel(ctx.author.id)) == 2:
self.jh.saveConfig()
self.jh.saveData()
self.tban.removeAllTextBan()
self.helpf.log("Bot is shutdown",2)
await ctx.bot.logout()
await bot.close()
sys.exit()
else:
await ctx.send(f"Your are not permitted to use this command.")
self.jh.saveConfig()
self.jh.saveData()
self.tban.removeAllTextBan()
await self.helpf.log("Bot is shutdown",2)
await ctx.bot.logout()
await bot.close()
sys.exit()

@commands.command(name='sendDPD', brief='Sends data protection declaration to channel')
@isBotOwner()
async def sendDPD(self, ctx):
if int(self.jh.getPrivilegeLevel(ctx.author.id)) == 2:
binpath = str(os.path.dirname(__file__))[:-4]+"/bin/"
string = ""
guilde = self.bot.get_guild(int(self.jh.getFromConfig("server")))
lenght = len(guilde.members)
i = 0
with open(binpath+"dataProtection.txt","r") as f:
string = f.read()
for member in guilde.members:
await self.helpf.removeRoles(member.id, ["chairman", "associate", "employee", "rookie"])
print(f"Progress: {i}/{lenght}")
i = i+1
message = await guilde.get_channel(int(self.jh.getFromConfig("loginchannel"))).send(string)
await message.add_reaction("✅")
else:
await ctx.send(f"Your are not permitted to use this command.")
binpath = str(os.path.dirname(__file__))[:-4]+"/bin/"
string = ""
guilde = self.bot.get_guild(int(self.jh.getFromConfig("guilde")))
lenght = len(guilde.members)
i = 0
with open(binpath+"dataProtection.txt","r") as f:
string = f.read()
for member in guilde.members:
await self.helpf.removeRoles(member.id, ["chairman", "associate", "employee", "rookie"])
print(f"Progress: {i}/{lenght}")
i = i+1
message = await ctx.send(string)
await message.add_reaction("✅")

@commands.command(name='sendGR', brief='Sends message to assing roles')
@isBotOwner()
async def sendGiveRoles(self, ctx):
if int(self.jh.getPrivilegeLevel(ctx.author.id)) == 2:
text = "**Choose your interest group**\n```You will be given roles based on your interest that grant you access to optional voice- and textchannels.\nInterest: Rolename:\n🎮 gaming gaming\n📚 study-channel student\n👾 development-technology dev-tech\n🏹 single-exchange single\n🤑 gambling-channel gambling\n⚡ bot-development bot-dev```"
guilde = self.bot.get_guild(int(self.jh.getFromConfig("server")))
lenght = len(guilde.members)
i = 1
for member in guilde.members:
await self.helpf.removeRoles(member.id, ["gaming", "student", "dev-tech", "single", "gambling", "bot-dev"])
print(f"Progress: {i}/{lenght}")
i = i+1
message = await guilde.get_channel(int(self.jh.getFromConfig("loginchannel"))).send(text)
reactionsarr = ["🎮","📚","👾","🏹","🤑","⚡"]
for emoji in reactionsarr:
await message.add_reaction(emoji)
else:
await ctx.send(f"Your are not permitted to use this command.")
text = "**Choose your interest group**\n```You will be given roles based on your interest that grant you access to optional voice- and textchannels.\nInterest: Rolename:\n🎮 gaming gaming\n📚 study-channel student\n👾 development-technology dev-tech\n🏹 single-exchange single\n🤑 gambling-channel gambling\n⚡ bot-development bot-dev```"
guilde = self.bot.get_guild(int(self.jh.getFromConfig("guilde")))
lenght = len(guilde.members)
i = 1
for member in guilde.members:
await self.helpf.removeRoles(member.id, ["gaming", "student", "dev-tech", "single", "gambling", "bot-dev"])
print(f"Progress: {i}/{lenght}")
i = i+1
message = await ctx.send(string)
reactionsarr = ["🎮","📚","👾","🏹","🤑","⚡"]
for emoji in reactionsarr:
await message.add_reaction(emoji)

@commands.command(name='changeBotMessage')
@isBotOwner()
async def changeBotMessage(self, ctx, channelID, messageID, text):
if int(self.jh.getPrivilegeLevel(ctx.author.id)) == 2:
message = await self.bot.get_channel(int(channelID)).fetch_message(int(messageID))
if (message.author != self.bot.user):
await ctx.send("Message is not from bot.")
return
if len(text) > 2000:
await ctx.send(f"Text is to long")
return
await message.edit(content=str(text))
else:
await ctx.send(f"Your are not permitted to use this command.")
message = await self.bot.get_channel(int(channelID)).fetch_message(int(messageID))
if (message.author != self.bot.user):
await ctx.send("Message is not from bot.")
return
if len(text) > 2000:
await ctx.send(f"Text is to long")
return
await message.edit(content=str(text))

@commands.command(name='addReaction')
@isBotOwner()
async def addReaction(self, ctx, channelID, messageID, emoji):
if int(self.jh.getPrivilegeLevel(ctx.author.id)) == 2:
message = await self.bot.get_channel(int(channelID)).fetch_message(int(messageID))
if (message.author != self.bot.user):
await ctx.send("Message is not from bot.")
return
try:
await message.add_reaction(emoji)
except InvalidArgument:
await ctx.send("No vaild emoji was sent by user.")
else:
await ctx.send(f"Your are not permitted to use this command.")
message = await self.bot.get_channel(int(channelID)).fetch_message(int(messageID))
if (message.author != self.bot.user):
await ctx.send("Message is not from bot.")
return
try:
await message.add_reaction(emoji)
except InvalidArgument:
await ctx.send("No vaild emoji was sent by user.")

def setup(bot, helpf, jh, xpf):
bot.add_cog(Commandmod(bot, helpf, tban, jh, xpf))
Loading

0 comments on commit 3567606

Please sign in to comment.