Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added cogs/__init__.py
Empty file.
8 changes: 3 additions & 5 deletions cogs/commandgiverole.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,7 @@ def search_table(self, channel_id, message_id):
table_temp = self.get_table_content(table_name)
table_mid = table_temp["messageid"]
table_cid = table_temp["channelid"]
if str(channel_id) == str(table_cid) and str(message_id) == str(
table_mid
):
if str(channel_id) == str(table_cid) and str(message_id) == str(table_mid):
table_content = table_temp
break
return table_content
Expand Down Expand Up @@ -462,5 +460,5 @@ def check_content_table(self, content):
return (True, None)


def setup(bot):
bot.add_cog(Commandgiverole(bot))
async def setup(bot):
await bot.add_cog(Commandgiverole(bot))
42 changes: 18 additions & 24 deletions cogs/commandlistener.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ def __init__(self, bot):

@commands.Cog.listener()
async def on_command_error(self, ctx, error):
print(
"Ignoring exception in command {}:".format(ctx.command), file=sys.stderr
)
print("Ignoring exception in command {}:".format(ctx.command), file=sys.stderr)
traceback.print_exception(
type(error), error, error.__traceback__, file=sys.stderr
)
Expand All @@ -50,7 +48,7 @@ async def on_ready(self):
# Sends message to mods, when bot is online
print("Now Online")
await self.utils.sendModsMessage(
"Bot is now online.\nVersion:\tDiscordBot DataBot v2.0.1"
"Bot is now online.\nVersion:\tDiscordBot DataBot v2.1.0"
)

# When a member joins a guild
Expand All @@ -61,8 +59,7 @@ async def on_member_join(self, member):

Creates a welcome message in the log channel
"""
channel = self.bot.get_channel(
int(self.jh.getFromConfig("logchannel")))
channel = self.bot.get_channel(int(self.jh.getFromConfig("logchannel")))
guild = self.bot.get_guild(int(self.jh.getFromConfig("guild")))
await channel.send(f"Hey **{member.mention}**, welcome to {guild}")

Expand All @@ -81,8 +78,7 @@ async def on_member_remove(self, member):

Sends a goodbye message in the log channel
"""
channel = self.bot.get_channel(
int(self.jh.getFromConfig("logchannel")))
channel = self.bot.get_channel(int(self.jh.getFromConfig("logchannel")))
guild = self.bot.get_guild(int(self.jh.getFromConfig("guild")))
await channel.send(
f"**{member.name}** has left {guild}. Press F to pay respect."
Expand All @@ -95,7 +91,7 @@ async def on_member_remove(self, member):
[hash, code] = self.utils.hashData(voice, text, textCount, member.id)
#Send user data
embed = discord.Embed(title=f"{member.nick} ({member.name})", color=12008408)
embed.set_thumbnail(url=member.avatar_url)
embed.set_thumbnail(url=member.avatar)
embed.add_field(name="VoiceXP", value=f"{voice}", inline=True)
embed.add_field(name="TextXP", value=f"{text}", inline=True)
embed.add_field(name="TextMessages", value=f"{textCount}", inline=True)
Expand Down Expand Up @@ -210,8 +206,7 @@ async def on_raw_reaction_add(self, payload):
not (message.author.bot or payload.member.bot)
and self.jh.getFromConfig("log") == "True"
):
self.jh.addReactionXP(
payload.user_id, self.xpf.randomRange(1, 5))
self.jh.addReactionXP(payload.user_id, self.xpf.randomRange(1, 5))
self.jh.saveData()

# When a user changes his voice state
Expand Down Expand Up @@ -247,10 +242,7 @@ async def on_voice_state_update(self, member, before, after):
and before.channel.name[-1].isdigit()
):
# Member left first channel
if (
before.channel.name[-1] == "1"
and not before.channel.name[-2].isdigit()
):
if before.channel.name[-1] == "1" and not before.channel.name[-2].isdigit():
# Delete last channel, which has no user in it

channelWithoutNumber = before.channel.name[:-1]
Expand Down Expand Up @@ -302,8 +294,7 @@ async def on_voice_state_update(self, member, before, after):
# in it
if afterNumber and len(
find(
lambda c: c.name == (
channelWithoutNumber + "1"), allChannel
lambda c: c.name == (channelWithoutNumber + "1"), allChannel
).members
):
# Get channels with after.channel.name without numbers in it and end
Expand Down Expand Up @@ -363,9 +354,10 @@ async def on_message(self, message):
a = "" + message.content

# Stops user from writting in levelchannel none command messages
if str(message.channel.id) == str(
self.jh.getFromConfig("levelchannel")
) and a[0] != self.jh.getFromConfig("command_prefix"):
print(a)
if str(message.channel.id) == str(self.jh.getFromConfig("levelchannel")) and a[
0
] != self.jh.getFromConfig("command_prefix"):
await message.delete()
return

Expand Down Expand Up @@ -400,11 +392,13 @@ async def on_message(self, message):
except Exception:
channelName = "DM"
string = (
"\n######\n# User "
"\n```User "
+ str(message.author.name)
+ "tried to invoke a command in "
+ str(channelName)
+ ".\n# Command: {a}\n######"
+ ".\nCommand: "
+ a
+ "```\n"
)
await self.utils.log(string, 2)

Expand Down Expand Up @@ -437,5 +431,5 @@ def _getLeaderboardChange(self, message):
return i


def setup(bot):
bot.add_cog(Commandlistener(bot))
async def setup(bot):
await bot.add_cog(Commandlistener(bot))
45 changes: 25 additions & 20 deletions cogs/commandmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,28 +100,33 @@ async def addtextwhitelist(self, ctx, channelID=None):

Adds channel to whitelist, so users can get XP in the channel.
"""
guild = self.bot.get_guild(self.jh.getFromConfig("guild"))
guild = self.bot.get_guild(int(self.jh.getFromConfig("guild")))
# This does not include threads
channels = self.bot.guilds[0].text_channels
# When channelID is not given, use ctx.channel.id.
if not channelID:
channelID = ctx.channel.id
# Test if channel is in Server
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 = (
"Added "
+ str(channelName)
+ " with ID "
+ str(channelID)
+ " to whitelist. This Text channel will be logged."
)
else:
message = "Channel is already in whitelist."
channel_to_add = ctx.channel
else:
message = f"Channel is not in the server {str(guild)}"
channel_to_add = self.bot.get_channel(int(channelID))

if not str(channelID) in [str(channel.id) for channel in channels]:
# Test if channel is in Server
message = f"Channel is not in the server {guild.name}"
await self.utils.log(f"{message} from user {ctx.author}", 2)

elif self.jh.writeToWhitelist(channelID):
# Try to write in whitelist
channelName = channel_to_add.name
message = (
"Added "
+ str(channelName)
+ " with ID "
+ str(channelID)
+ " to whitelist. This Text channel will be logged."
)
else:
message = "Channel is already in whitelist."
await ctx.send(message)

@textwl.command(name="rm", brief="Removes a text channel from the whitelist")
Expand Down Expand Up @@ -224,7 +229,7 @@ async def addblacklist(self, ctx, channelID):

Adds channel to whitelist, so users can not get XP in the channel.
"""
guild = self.bot.get_guild(self.jh.getFromConfig("guild"))
guild = self.bot.get_guild(int(self.jh.getFromConfig("guild")))
channels = self.bot.guilds[0].voice_channels
# Test if channel is in Server
if str(channelID) in [str(channel.id) for channel in channels]:
Expand All @@ -241,7 +246,7 @@ async def addblacklist(self, ctx, channelID):
else:
message = "Channel is already in blacklist."
else:
message = f"Channel is not in the server {str(guild)}"
message = f"Channel is not in the server {guild.name}"
await self.utils.log(f"{message} from user {ctx.author}", 2)
await ctx.send(message)

Expand Down Expand Up @@ -342,5 +347,5 @@ async def printData(self, ctx):
await ctx.send(f"```{message}```")


def setup(bot):
bot.add_cog(Commandmod(bot))
async def setup(bot):
await bot.add_cog(Commandmod(bot))
4 changes: 2 additions & 2 deletions cogs/commandmodserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ def __init__(self, bot):
Commandmodserver.utils = self.utils


def setup(bot):
bot.add_cog(Commandmodserver(bot))
async def setup(bot):
await bot.add_cog(Commandmodserver(bot))
22 changes: 9 additions & 13 deletions cogs/commandowner.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os

from discord import InvalidArgument
from discord import NotFound
from discord.ext import commands

from helpfunctions.decorators import isBotOwnerCommand
Expand Down Expand Up @@ -87,9 +87,7 @@ async def stoplog(self, ctx):
guildName = str(self.bot.get_guild(guildID))
self.jh.config["log"] = "False"
self.jh.saveConfig()
await self.utils.log(
f"Stopped to log users from Server:\n\t{guildName}", 2
)
await self.utils.log(f"Stopped to log users from Server:\n\t{guildName}", 2)
else:
await ctx.send("Bot is NOT logging. Logging state: False")

Expand Down Expand Up @@ -139,7 +137,7 @@ async def addReaction(self, ctx, channelID, messageID, emoji):
return
try:
await message.add_reaction(emoji)
except InvalidArgument:
except NotFound:
await ctx.send("No vaild emoji was sent by user.")

@commands.command(name="rlext")
Expand All @@ -161,19 +159,17 @@ async def reloadExtensions(self, ctx, *extensions):
[
"cogs." + ext[:-3]
for ext in os.listdir("./")
if ext.endswith(".py")
if ext.endswith(".py") and not ext.startswith("__")
]
)
reloadedExtensions = []
for ext in extensions:
if ext in self.bot.extensions:
self.bot.unload_extension(ext)
self.bot.load_extension(ext)
await self.bot.unload_extension(ext)
await self.bot.load_extension(ext)
reloadedExtensions.append(ext)
await self.utils.log(
f"Reloaded extensions: {', '.join(reloadedExtensions)}", 2
)
await self.utils.log(f"Reloaded extensions: {', '.join(reloadedExtensions)}", 2)


def setup(bot):
bot.add_cog(Commandowner(bot))
async def setup(bot):
await bot.add_cog(Commandowner(bot))
4 changes: 2 additions & 2 deletions cogs/commandpoll.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,5 +635,5 @@ def votedOption(self, message):
return i


def setup(bot):
bot.add_cog(Commandpoll(bot))
async def setup(bot):
await bot.add_cog(Commandpoll(bot))
14 changes: 5 additions & 9 deletions cogs/commandsubroutine.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@ async def removeRoleSubroutineFunction(self, currentTime, bufferTime, guild):
log_message,
2,
)
if (
currentTime - offset
) % interval < bufferTime and currentTime > offset:
if (currentTime - offset) % interval < bufferTime and currentTime > offset:
role = guild.get_role(int(toRemove))
if role is None:
log_message = (
Expand Down Expand Up @@ -236,8 +234,7 @@ def addMembersOnlineVoiceXp(self, serverid):
# Total all connected members
for channel in voiceChanels:
membersInChannel = [
member for member in channel.members if not member.bot
]
member for member in channel.members if not member.bot]
# Check if more than one person is in channel
if len(membersInChannel) >= 2:
membersNotMutedOrBot = [
Expand All @@ -246,8 +243,7 @@ def addMembersOnlineVoiceXp(self, serverid):
if not (member.voice.self_mute or member.bot)
]
self.jh.addAllUserVoice(
[member.id for member in membersNotMutedOrBot]
)
[member.id for member in membersNotMutedOrBot])
# Extra XP
membersStreamOrVideo = [
member
Expand Down Expand Up @@ -281,5 +277,5 @@ async def levelAkk(self):
)


def setup(bot):
bot.add_cog(Subroutine(bot))
async def setup(bot):
await bot.add_cog(Subroutine(bot))
7 changes: 3 additions & 4 deletions cogs/commandsubserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,8 +658,7 @@ def get_all_subserver_roles(self):
# Sort by subserver name. '+ r.name[1]' is for sorting sub roles on top of
# subway roles, since '+ r.name[1]' is 'u' or 'w'.
sorted_roles = sorted(
sub_roles, key=lambda r: r.name.split("-")[1] + r.name[1]
)
sub_roles, key=lambda r: r.name.split("-")[1] + r.name[1])
if not sorted_roles:
return []
# Data pattern: [(sub-a, sw-a), ...]
Expand Down Expand Up @@ -809,5 +808,5 @@ def hash_invite_code(self, subserver_name):
return code[:8]


def setup(bot):
bot.add_cog(Commandsubserver(bot))
async def setup(bot):
await bot.add_cog(Commandsubserver(bot))
10 changes: 4 additions & 6 deletions cogs/commanduser.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,7 @@ async def textunban(self, ctx, userID):
f"User {ctx.author.mention} textunbaned {user.mention}"
)
else:
await ctx.send(
content="ERROR: User has no textban.", delete_after=3600
)
await ctx.send(content="ERROR: User has no textban.", delete_after=3600)

"""
# When give star of the week should be queued
Expand Down Expand Up @@ -647,7 +645,7 @@ async def getLevel(self, ctx, *inputs):
return
self.jh.addNewDataEntry(userID)
# Create Embeded
avatar_url = member.avatar_url
avatar_url = member.avatar
level = self.jh.getUserLevel(userID)
voiceXP = self.jh.getUserVoice(userID)
textXP = self.jh.getUserText(userID)
Expand Down Expand Up @@ -752,5 +750,5 @@ async def reclaimData(self, ctx, voice, text, textCount, code, hash):
"""


def setup(bot):
bot.add_cog(Commanduser(bot))
async def setup(bot):
await bot.add_cog(Commanduser(bot))
Empty file added datahandler/__init__.py
Empty file.
Empty file added helpfunctions/__init__.py
Empty file.
Loading