Skip to content

Commit e0e13b8

Browse files
authored
Merge pull request #15 from PantomInach/testing
Push working Bot to main
2 parents 6300bb3 + d209096 commit e0e13b8

24 files changed

Lines changed: 2107 additions & 0 deletions

bin/config.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"token": "Your Token",
3+
"command_prefix": "+",
4+
"log": "False",
5+
"logchannel": "",
6+
"levelchannel":"",
7+
"spamchannel":"",
8+
"infochannel":"",
9+
"owner": "",
10+
"textCooldown": "",
11+
"privilege": {
12+
13+
},
14+
"server": "",
15+
"serverVoiceBlacklist": [
16+
"0",
17+
],
18+
"serverTextWhitelist": [
19+
"0",
20+
],
21+
"roles": [
22+
23+
],
24+
"rolesXPNeed": [
25+
26+
]
27+
}

bin/counter.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

bin/data.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

bin/dataProtection.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
**Note on data processing (A00002b)**
2+
```This Discord-Server uses a self-programmed bot, based on Discords own API, to collect and process user data.
3+
The bot shown as "PantomDataBot#3363" ("z +level" in member list) tracks the following:
4+
- Number of written messages in every text-channel
5+
- Length of written messages in every text-channel
6+
- Giving of reactions to written messages in every text-channel
7+
- Number of active users and active UserID in every voice-channel
8+
- Mute-status of every active user in every voice-channel
9+
- Camera- and LIVE-status of every active user in every voice-channel
10+
- Every reaction to bot-messages in every text-channel for bot-interaction
11+
- Time of user-messages in every text-channel
12+
- User-Messages with "+" prefix in every text-channel
13+
- Time of given user-roles
14+
- Time of gained experience-points for being active in voice-channels
15+
- Every direct-message you send the bot “PantomDataBot#3363“
16+
17+
The Bot shown as "PantomDataBot#3363" ("z +level" in member list) DOES NOT track the following:
18+
- Content of written user-messages in every text-channel without "+" prefix
19+
- Content of given reactions to any written user-messages in every text-channel
20+
- Any content of transferred voice or video in voice-channels
21+
22+
All named aspects are part of server-own features like getting roles by pressing bot-reactions, banning users in text-channels and gaining roles by leveling. Data is stored and processed combined with Discords User-ID and won’t be hand out to third parties.
23+
The text-channel “level” features a leaderboard with the usernames and their hours spend on the server, the number of their written messages as well as the amount of gained experience-points by doing it.
24+
By leaving the server, all user-related data will be deleted from the server after 14 days without rejoining.
25+
26+
By clicking on the bot-reaction you accept the named aspects above.
27+
Have fun on our server,
28+
your admins and mods```

bin/datenschutz.txt

Whitespace-only changes.

bin/log.txt

Whitespace-only changes.

bin/poll.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

bin/test.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import json
2+
import os
3+
4+
print(str(os.path.dirname(__file__))+"/data.json")
5+
data = json.load(open(str(os.path.dirname(__file__))+"/data.json"))
6+
7+
a=sorted(data, key=lambda id: int(data[id]["Level"]) if int(data[id]["Level"]) > 5 else -int(data[id]["Level"]))
8+
print(a)

bin/textban.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

bot/commandmod.py

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
import discord
2+
from discord.utils import get
3+
from discord.ext import commands
4+
from .jsonhandel import Jsonhandel
5+
from .xpfunk import Xpfunk
6+
from .helpfunc import Helpfunc
7+
8+
class Commandmod(commands.Cog, name='Bot Mod Commands'):
9+
"""You need privilage level 1 to use these commands."""
10+
def __init__(self, bot, helpf, jh, xpf):
11+
super(Commandmod, self).__init__()
12+
self.bot = bot
13+
self.helpf = helpf
14+
self.jh = jh
15+
self.xpf = xpf
16+
17+
#Adds channel to blacklist
18+
@commands.command(name='addvoiceblacklist', brief='Adds a voice channel to the blacklist.', description='You need privilege level 1 to use this command. You can add a voice channel to the blacklist. The users in blacklisted channels will not get voice XP. As an input you need the channel id, which you can get by rigth clicking on the channel.')
19+
async def addblacklist(self, ctx, channelID):
20+
message = "Your are not permitted to use this command. You need Mod privileges"
21+
if int(self.jh.getPrivilegeLevel(ctx.author.id)) > 0:
22+
server = self.bot.get_guild(self.jh.getFromConfig("server"))
23+
channels = await self.helpf.channelList(self.jh.getFromConfig("server"))
24+
#Test if channel is in Server
25+
if str(channelID) in channels:
26+
#Try to write in Blacklist
27+
if self.jh.writeToBalcklist(channelID):
28+
channelName = str(self.bot.get_channel(int(channelID)))
29+
message = f"Added {channelName} with id {channelID} to Blacklist. This Voice channel will not be logged."
30+
else:
31+
message = "Channel is already in Blacklist."
32+
else:
33+
message = f"Channel is not in the server {str(server)}"
34+
author = ctx.author
35+
await self.helpf.log(f"{message} from user {author}",2)
36+
await ctx.send(message)
37+
38+
#Removes channels from blacklist
39+
@commands.command(name='removevoiceblacklist', brief='Removes a voice channel to the blacklist.', description='You need privilege level 1 to use this command. You can remove a voice channel from the blacklist. The users in this channel will get voice XP. As an input you need the channel id, which you can get by rigth clicking on the channel.')
40+
async def removeblacklist(self, ctx, channelID):
41+
message = "Your are not permitted to use this command. You need Mod privileges"
42+
if int(self.jh.getPrivilegeLevel(ctx.author.id)) > 0:
43+
#Try to remove from Blacklist
44+
if self.jh.removeFromBalcklist(channelID):
45+
channelName = str(self.bot.get_channel(int(channelID)))
46+
message = f"Removed {channelName} with id {channelID} from Blacklist. This Voice channel will be logged."
47+
else:
48+
message = "Channel does not exist or is not in Blacklist"
49+
author = ctx.author
50+
await self.helpf.log(f"{message} from user {author}",2)
51+
await ctx.send(message)
52+
53+
#Adds text channel to whitelist
54+
@commands.command(name='addtextwhitelist', brief='Adds a text channel to the whitelist.', description='You need privilege level 1 to use this command. You can add a text channel to the whitelist. Users writting in channels from the whitelist will get text XP. As an input you need the channel id, which you can get by rigth clicking on the channel.')
55+
async def addtextwhitelist(self, ctx, channelID):
56+
message = "Your are not permitted to use this command. You need Mod privileges"
57+
if int(self.jh.getPrivilegeLevel(ctx.author.id)) > 0:
58+
server = self.bot.get_guild(self.jh.getFromConfig("server"))
59+
channels = await self.helpf.channelList(self.jh.getFromConfig("server"))
60+
#Test if channel is in Server
61+
if str(channelID) in channels:
62+
#Try to write in whitelist
63+
if self.jh.writeToWhitelist(channelID):
64+
channelName = str(self.bot.get_channel(int(channelID)))
65+
message = f"Added {channelName} with id {channelID} to Whitelist. This Text channel will be logged."
66+
else:
67+
message = "Channel is already in Whitelist."
68+
else:
69+
message = f"Channel is not in the server {str(server)}"
70+
author = ctx.author
71+
await self.helpf.log(f"{message} from user {author}",2)
72+
await ctx.send(message)
73+
74+
#Removes text channel from whitelist
75+
@commands.command(name='removetextwhitelist', brief='Removes a text channel to the whitelist.', description='You need privilege level 1 to use this command. You can remove text channels from the whitelist. Users writting in channels from the whitelist will get not get text XP. As an input you need the channel id, which you can get by rigth clicking on the channel.')
76+
async def removetextwhitelist(self, ctx, channelID):
77+
message = "Your are not permitted to use this command. You need Mod privileges"
78+
if int(self.jh.getPrivilegeLevel(ctx.author.id)) > 0:
79+
#Try to remove from whitelist
80+
if self.jh.removeFromWhitelist(channelID):
81+
channelName = str(self.bot.get_channel(int(channelID)))
82+
message = f"Removed {channelName} with id {channelID} from Whitelist. This Text channel will not be logged."
83+
else:
84+
message = "Channel does not exist or is not in Whitelist"
85+
author = ctx.author
86+
await self.helpf.log(f"{message} from user {author}",2)
87+
await ctx.send(message)
88+
89+
#TODO: Does not creat new user. Use somehow jh.addNewDataEntry(userID)
90+
@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.')
91+
async def getUserData(self, ctx, userID):
92+
message = "Your are not permitted to use this command. You need Mod privileges"
93+
if int(self.jh.getPrivilegeLevel(ctx.author.id)) > 0:
94+
if self.jh.isInData(userID):
95+
userData = self.jh.data[str(userID)]
96+
voice = userData["Voice"]
97+
text = userData["Text"]
98+
textCount = userData["TextCount"]
99+
message = f"User: {str(self.bot.get_user(int(userID)))} VoiceXP: {voice} TextXP: {text} TextCount: {textCount}"
100+
else:
101+
user = self.bot.get_user(int(userID))
102+
message = f"User was not in data. Created user: {user.mention}"
103+
await ctx.send(message)
104+
105+
#TODO: Does not creat new user. Use somehow jh.addNewDataEntry(userID)
106+
@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.')
107+
async def setVoiceXP(self, ctx, userID, amount):
108+
message = "Your are not permitted to use this command. You need Mod privileges"
109+
if int(self.jh.getPrivilegeLevel(ctx.author.id)) > 0:
110+
message = ""
111+
if not self.jh.isInData(userID):
112+
message = f"User was not in data. Created user: {self.bot.get_user(int(userID))}\n"
113+
self.jh.addNewDataEntry(userID)
114+
self.jh.data[str(userID)]["Voice"] = str(amount)
115+
self.jh.saveData()
116+
message += f"Set user {str(self.bot.get_user(int(userID)))} voiceXP to{amount}."
117+
await self.helpf.log(f"User {ctx.author} set user {str(self.bot.get_user(int(userID)))} voiceXP to {amount}.",2)
118+
await ctx.send(message)
119+
120+
#TODO: Does not creat new user. Use somehow jh.addNewDataEntry(userID)
121+
@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.')
122+
async def setTextXP(self, ctx, userID, amount):
123+
message = "Your are not permitted to use this command. You need Mod privileges"
124+
if int(self.jh.getPrivilegeLevel(ctx.author.id)) > 0:
125+
message = ""
126+
if not self.jh.isInData(userID):
127+
message = f"User was not in data. Created user: {self.bot.get_user(int(userID))}\n"
128+
self.jh.addNewDataEntry(userID)
129+
self.jh.data[str(userID)]["Text"] = str(amount)
130+
self.jh.saveData()
131+
message += f"Set user {str(self.bot.get_user(int(userID)))} textXP to {amount}."
132+
await self.helpf.log(f"User {ctx.author} set user {str(self.bot.get_user(int(userID)))} textXP to {amount}.",2)
133+
await ctx.send(message)
134+
135+
#TODO: Does not creat new user. Use somehow jh.addNewDataEntry(userID)
136+
@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.')
137+
async def setTextCount(self, ctx, userID, amount):
138+
message = "Your are not permitted to use this command. You need Mod privileges"
139+
if int(self.jh.getPrivilegeLevel(ctx.author.id)) > 0:
140+
message = ""
141+
if not self.jh.isInData(userID):
142+
message = f"User was not in data. Created user: {self.bot.get_user(int(userID))}\n"
143+
self.jh.addNewDataEntry(userID)
144+
self.jh.data[str(userID)]["TextCount"] = str(amount)
145+
self.jh.saveData()
146+
message += f"Set user {str(self.bot.get_user(int(userID)))} TextCount to {amount}."
147+
await self.helpf.log(f"User {ctx.author} set user {str(self.bot.get_user(int(userID)))} textCount to {amount}.",2)
148+
await ctx.send(message)
149+
150+
@commands.command(name='printdata', brief='Prints the Data of the Users', description='You need privilege level 1 to use this command. Prints the Username, userID, level, voiceXP, textXP and textCount off all users on the server.')
151+
async def printData(self,ctx):
152+
message = "Your are not permitted to use this command. You need Mod privileges"
153+
if int(self.jh.getPrivilegeLevel(ctx.author.id)) > 0:
154+
server = str(self.bot.get_guild(int(self.jh.getFromConfig("server"))))
155+
message = f"Printing data of server {server}:\n"
156+
# Sorts user by there usernames
157+
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")
158+
for userID in sortedData:
159+
temp = self.jh.data[str(userID)]
160+
level = temp["Level"]
161+
voiceXP = temp["Voice"]
162+
textXP = temp["Text"]
163+
textCount = temp["TextCount"]
164+
user = self.bot.get_user(int(userID))
165+
username = "No User"
166+
#Handel not existing UserIDs
167+
if user != None:
168+
username = user.name
169+
messageadd = f"\nUser: {username}, UserID: {userID}, Level: {level}, VoiceXP: {voiceXP}, TextXP: {textXP}, Messages: {textCount}."
170+
if len(message)+len(messageadd)>2000: #Get around 2000 char discord text limit
171+
await ctx.send(message)
172+
message = ""
173+
message +=messageadd
174+
print(f"User {ctx.author} prints all data in {ctx.channel}.")
175+
await ctx.send(message)
176+
177+
@commands.command(name='removeuser', brief='Removes user from data.', description='You need privilege level 1 to use this command. Removes the userID from the data und save it. As an input you need the userID, which you can get by rigth clicking on the user.')
178+
async def removeuser(self, ctx, userID):
179+
message = "Your are not permitted to use this command. You need Mod privileges"
180+
if int(self.jh.getPrivilegeLevel(ctx.author.id)) > 0:
181+
if self.jh.removeUserFromData(userID) == 1:
182+
user = self.bot.get_user(int(userID))
183+
username = "No User"
184+
if user != None:
185+
username = user.name
186+
message = f"Removed User {username} with ID {userID} from Data."
187+
else:
188+
message = f"User with ID {userID} is not in data."
189+
await self.helpf.log(f"User {ctx.author}: {message}",2)
190+
await ctx.send(message)
191+
192+
def setup(bot, helpf, jh, xpf):
193+
bot.add_cog(Commandmod(bot, helpf, jh, xpf))

0 commit comments

Comments
 (0)