Skip to content

Commit 962dc2e

Browse files
committed
Updates and prepare for for Presentation
- Created ServerStats class, API endpoint, settings, and event triggers - Added cog descriptions - Renamed a few command functions to include _ for spaces - Hid the dallas command - Created nick command - Updated LeagueCommands embed pages - Fixed typo in league process_reactions where list_type was missing for "go back" - Updates strike; Striker is now stored by id instead of name, and fixed embed footer saying "kicked by" instead of "striked by" - Removed set_log_channel and config command - Create prune command for message pruning - Disabled NSFW commands - Removed dead code from stats command - Rewrote the help command to use page embeds and be more dynamic to use less repeated code
1 parent 9166bd7 commit 962dc2e

12 files changed

+329
-195
lines changed

bot.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from requests_oauthlib import OAuth2Session
1616

1717
from utils import loadAllCogs, loadAllExtensions, SetupLogger, RedisClient, Mongo, APIServer, ServerSettings, getLogger, \
18-
UserProfiles, BotAdmins, getSystemLogChannel, Converter
18+
UserProfiles, BotAdmins, getSystemLogChannel, Converter, ServerStats
1919

2020
# get asyncio loop
2121
loop = asyncio.get_event_loop()
@@ -871,6 +871,19 @@ def server_toggle_module(server_id):
871871
pass
872872
except discord.HTTPException:
873873
pass
874+
elif module.lower() == "server_stats":
875+
if enabled:
876+
enable_fut = asyncio.run_coroutine_threadsafe(
877+
ServerStats(bot, server).enable(),
878+
loop
879+
)
880+
enable_fut.result()
881+
else:
882+
disable_fut = asyncio.run_coroutine_threadsafe(
883+
ServerStats(bot, server).disable(),
884+
loop
885+
)
886+
disable_fut.result()
874887
return "Settings Updated", 200
875888
else:
876889
return "", 400

cogs/BotAdminCommands.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
import ast
2-
import inspect
32
from datetime import datetime
43

54
import discord
65
from discord.ext import commands
6+
77
import utils
88
from utils import UserProfiles, getLogger, getSystemLogChannel, BotAdmins
99
from .utils import checks
1010

1111

1212
class BotAdminCommandsCog(commands.Cog):
13+
"""Commands for Bot Admins"""
1314
def __init__(self, bot):
1415
self.bot = bot
1516

1617
@commands.command(name="reloadcog", hidden=True, help="Reloads a cog")
1718
@checks.isBotAdmin()
18-
async def reloadcog(self, ctx, *, cog: str):
19+
async def reload_cog(self, ctx, *, cog: str):
1920
# to reload we need to unload it first
2021
try:
2122
self.bot.unload_extension(f"cogs.{cog}")
@@ -29,7 +30,7 @@ async def reloadcog(self, ctx, *, cog: str):
2930

3031
@commands.command(name="loadcog", hidden=True, help="Loads a cog")
3132
@checks.isBotAdmin()
32-
async def loadcog(self, ctx, *, cog: str):
33+
async def load_cog(self, ctx, *, cog: str):
3334
# try to load cog
3435
try:
3536
self.bot.load_extension(f"cogs.{cog}")
@@ -42,7 +43,7 @@ async def loadcog(self, ctx, *, cog: str):
4243

4344
@commands.command(name="unloadcog", hidden=True, help="Unloads a cog")
4445
@checks.isBotAdmin()
45-
async def unloadcog(self, ctx, *, cog: str):
46+
async def unload_cog(self, ctx, *, cog: str):
4647
try:
4748
self.bot.unload_extension(f"cogs.{cog}")
4849
except Exception as e:
@@ -54,7 +55,7 @@ async def unloadcog(self, ctx, *, cog: str):
5455

5556
@commands.command(name="reloadext", hidden=True, help="Reloads an extension")
5657
@checks.isBotAdmin()
57-
async def reloadext(self, ctx, *, ext: str):
58+
async def reload_ext(self, ctx, *, ext: str):
5859
# to reload we need to unload it first
5960
try:
6061
self.bot.unload_extension(f"extensions.{ext}")
@@ -68,7 +69,7 @@ async def reloadext(self, ctx, *, ext: str):
6869

6970
@commands.command(name="loadext", hidden=True, help="Loads an extension")
7071
@checks.isBotAdmin()
71-
async def loadext(self, ctx, *, ext: str):
72+
async def load_ext(self, ctx, *, ext: str):
7273
# try to load cog
7374
try:
7475
self.bot.load_extension(f"extensions.{ext}")
@@ -81,7 +82,7 @@ async def loadext(self, ctx, *, ext: str):
8182

8283
@commands.command(name="unloadext", hidden=True, help="Unloads an extension")
8384
@checks.isBotAdmin()
84-
async def unloadext(self, ctx, *, ext: str):
85+
async def unload_ext(self, ctx, *, ext: str):
8586
try:
8687
self.bot.unload_extension(f"extensions.{ext}")
8788
except Exception as e:

cogs/FunCommands.py

+34-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
import asyncio
22
import random
33
from datetime import datetime
4-
from exchanges import *
4+
55
import discord
66
import requests
77
from discord import Forbidden, HTTPException, InvalidArgument, NotFound
88
from discord.ext import commands
9+
from exchanges import *
910
from prawcore import exceptions
1011

11-
from utils import getRandomFact, RedditClient
12+
from utils import getRandomFact, RedditClient, getLogger
1213

1314

1415
class FunCommandsCog(commands.Cog):
16+
"""Misc commands for fun with not specific usage"""
1517
def __init__(self, bot):
1618
self.bot = bot
1719

@@ -119,7 +121,7 @@ async def rob(self, ctx, member: discord.Member):
119121
embed.set_author(name=self.bot.user.name, icon_url=self.bot.user.avatar_url)
120122
await ctx.send(content=None, embed=embed)
121123

122-
@commands.command(name="dallas", help="Dallas is a fucking furry")
124+
@commands.command(name="dallas", help="Dallas is a fucking furry", hidden=True)
123125
@commands.guild_only()
124126
async def dallas(self, ctx):
125127
embed = discord.Embed(title=None,
@@ -290,7 +292,8 @@ async def alex_jones(self, ctx):
290292
embed = discord.Embed(title=None,
291293
description=None,
292294
color=discord.Color.green(), timestamp=datetime.utcnow())
293-
embed.set_image(url="https://media.discordapp.net/attachments/644927766197698593/647167462315393053/ezgif.com-video-to-gif.gif")
295+
embed.set_image(
296+
url="https://media.discordapp.net/attachments/644927766197698593/647167462315393053/ezgif.com-video-to-gif.gif")
294297
embed.set_footer(text=ctx.message.author.name, icon_url=ctx.message.author.avatar_url)
295298
embed.set_author(name=self.bot.user.name, icon_url=self.bot.user.avatar_url)
296299
await ctx.send(content=None, embed=embed)
@@ -532,7 +535,8 @@ async def meme(self, ctx, subreddit: str = "funny", listing_type: str = "new"):
532535
print(f"[FunCommands] Cought error in meme command! Error: {e}")
533536
return await ctx.send(f"An error occured!")
534537

535-
@commands.command(name="bitcoin", help="List exchanges, get current price for an exchange", description="Get current bitcoin price for an exchange")
538+
@commands.command(name="bitcoin", help="List exchanges, get current price for an exchange",
539+
description="Get current bitcoin price for an exchange")
536540
@commands.guild_only()
537541
async def bitcoin(self, ctx, arg=None):
538542
if arg is not None:
@@ -634,6 +638,31 @@ async def bitcoin(self, ctx, arg=None):
634638
embed.set_thumbnail(url="https://miro.medium.com/max/3150/2*O3o3Gdam4S5MSXfUg_UxGg.png")
635639
return await ctx.send(content=None, embed=embed)
636640

641+
@commands.command(name="nick", help="Change nickname of a user", usage="<nickname> [user]")
642+
@commands.guild_only()
643+
@commands.bot_has_permissions(manage_nicknames=True)
644+
async def nick(self, ctx, nick: str, member: discord.Member = None):
645+
user = ctx.author if member is None else member
646+
try:
647+
await user.edit(nick=nick)
648+
embed = discord.Embed(title=f"Nickname updated for {user}!", description=None,
649+
color=discord.Color.green(),
650+
timestamp=datetime.utcnow())
651+
await ctx.send(content=None, embed=embed, delete_after=10)
652+
except Forbidden:
653+
# missing permission
654+
getLogger().debug(f"[Nick] Missing permissions to change nickname for {user}!")
655+
embed = discord.Embed(title=f"Missing permissions to change nickname for {user}!", description=None, color=discord.Color.red(),
656+
timestamp=datetime.utcnow())
657+
await ctx.send(content=None, embed=embed, delete_after=10)
658+
except HTTPException:
659+
# Failed to edit user
660+
getLogger().debug(f"[Nick] failed to set nickname!")
661+
embed = discord.Embed(title=f"failed to set nickname for {user}!", description=None,
662+
color=discord.Color.red(),
663+
timestamp=datetime.utcnow())
664+
await ctx.send(content=None, embed=embed, delete_after=10)
665+
637666

638667
def getPostsByListingType(subreddit: str, type: str):
639668
if type == "top":

cogs/GameCommands.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66

77

88
class GameCommandsCog(commands.Cog):
9+
"""Commands for Games"""
910
def __init__(self, bot):
1011
self.bot = bot
1112

1213
@commands.command(name="rpgstart")
1314
@commands.guild_only()
14-
async def rpgstart(self, ctx):
15+
async def rpg_start(self, ctx):
1516
profile = UserProfiles(ctx.author)
1617
profile_data = profile.getUserProfile()
1718
isCreated = profile_data["RPGData"]["CreatedCharacter"]
@@ -109,7 +110,7 @@ def check(message):
109110

110111
@commands.command(name="rpgprofile")
111112
@commands.guild_only()
112-
async def rpgprofile(self, ctx, member=discord.Member):
113+
async def rpg_profile(self, ctx, member=discord.Member):
113114
profile = UserProfiles(ctx.author)
114115
profile_data = profile.getUserProfile()
115116
a = profile_data['RPGData']['Name']

cogs/GuildEvents.py

+26-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import discord
22
from datetime import datetime
33
import utils
4-
from utils import utc_to_epoch, ServerSettings
4+
from utils import utc_to_epoch, ServerSettings, ServerStats
55
from discord.ext import commands
66
from utils import UserProfiles
77

@@ -31,6 +31,10 @@ async def on_member_join(self, member):
3131
embed.set_footer(text=self.bot.user.name, icon_url=self.bot.user.avatar_url)
3232
await log_channel.send(content=None, embed=embed)
3333

34+
stats = ServerStats(self.bot, member.guild)
35+
if stats.isEnabled():
36+
await stats.update()
37+
3438
@commands.Cog.listener()
3539
async def on_member_remove(self, member):
3640

@@ -65,6 +69,10 @@ async def on_member_remove(self, member):
6569
embed.set_footer(text=self.bot.user.name, icon_url=self.bot.user.avatar_url)
6670
await log_channel.send(content=None, embed=embed)
6771

72+
stats = ServerStats(self.bot, member.guild)
73+
if stats.isEnabled():
74+
await stats.update()
75+
6876
# commented out in favor of the message sent from the ban command
6977
# @commands.Cog.listener()
7078
# async def on_member_ban(self, guild: discord.Guild, member: discord.Member):
@@ -160,6 +168,10 @@ async def on_guild_channel_create(self, channel: discord.abc.GuildChannel):
160168
if log_channel is not None and enabled:
161169
await log_channel.send(f"Channel created: {channel.mention} [{channel.name}] ({channel.id})")
162170

171+
stats = ServerStats(self.bot, channel.guild)
172+
if stats.isEnabled():
173+
await stats.update()
174+
163175
@commands.Cog.listener()
164176
async def on_guild_channel_delete(self, channel: discord.abc.GuildChannel):
165177
server_settings = ServerSettings(channel.guild).getServerSettings()
@@ -169,6 +181,10 @@ async def on_guild_channel_delete(self, channel: discord.abc.GuildChannel):
169181
if log_channel is not None and enabled:
170182
await log_channel.send(f"Channel deleted: {channel.name} ({channel.id})")
171183

184+
stats = ServerStats(self.bot, channel.guild)
185+
if stats.isEnabled():
186+
await stats.update()
187+
172188
@commands.Cog.listener()
173189
async def on_guild_update(self, before: discord.Guild, after: discord.Guild):
174190
# TODO: Make this an embed
@@ -198,6 +214,10 @@ async def on_guild_role_create(self, role: discord.Role):
198214
if log_channel is not None and enabled:
199215
await log_channel.send(content=None, embed=embed)
200216

217+
stats = ServerStats(self.bot, role.guild)
218+
if stats.isEnabled():
219+
await stats.update()
220+
201221
@commands.Cog.listener()
202222
async def on_guild_role_delete(self, role: discord.Role):
203223
server_settings = ServerSettings(role.guild).getServerSettings()
@@ -212,6 +232,10 @@ async def on_guild_role_delete(self, role: discord.Role):
212232
if log_channel is not None and enabled:
213233
await log_channel.send(content=None, embed=embed)
214234

235+
stats = ServerStats(self.bot, role.guild)
236+
if stats.isEnabled():
237+
await stats.update()
238+
215239
@commands.Cog.listener()
216240
async def on_guild_role_update(self, before: discord.Role, after: discord.Role):
217241
# TODO: Make this an embed
@@ -242,4 +266,4 @@ async def on_guild_emojis_update(self, guild: discord.Guild, before: discord.Emo
242266

243267

244268
def setup(bot):
245-
bot.add_cog(GuildEventsCog(bot))
269+
bot.add_cog(GuildEventsCog(bot))

cogs/LeagueCommands.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111

1212
class LeagueCommandsCog(commands.Cog):
13+
"""Commands for League of Legends module"""
1314
def __init__(self, bot):
1415
self.bot = bot
1516
self.boots_list = [
@@ -62,17 +63,17 @@ async def process_reactions(self, ctx, message, page, pagination, list_type):
6263
new_embed.set_footer(text=ctx.message.author.name, icon_url=ctx.message.author.avatar_url)
6364
new_embed.set_author(name=self.bot.user.name, icon_url=self.bot.user.avatar_url)
6465
await message.clear_reactions()
65-
if page + 2 >= 1 or page + 2 == len(pagination):
66+
if page + 1 >= 1 or page + 1 == len(pagination):
6667
await message.add_reaction("⬅")
67-
if page + 2 <= 1 or page + 2 < len(pagination):
68+
if page + 1 <= 1 or page + 1 < len(pagination):
6869
await message.add_reaction("➡")
6970
await message.add_reaction("❌")
7071

7172
await message.edit(content=None, embed=new_embed)
7273
await self.process_reactions(ctx, message, page, pagination, list_type)
7374
elif reaction.emoji == "⬅":
7475
page -= 1
75-
new_embed = discord.Embed(title=f"Page {page + 1} of {len(pagination)} - Champions List",
76+
new_embed = discord.Embed(title=f"Page {page + 1} of {len(pagination)} - {list_type} List",
7677
description="\n".join(pagination[page]),
7778
color=discord.Color.orange(),
7879
timestamp=datetime.utcnow())
@@ -108,7 +109,7 @@ async def league(self, ctx, decider: str, decider2: str = None):
108109
embed.set_author(name=self.bot.user.name, icon_url=self.bot.user.avatar_url)
109110

110111
champion_list_message = await ctx.send(content=None, embed=embed)
111-
if page + 2 <= 1 or page + 2 < len(pagination):
112+
if page + 1 <= 1 or page + 1 < len(pagination):
112113
await champion_list_message.add_reaction("➡")
113114
await champion_list_message.add_reaction("❌")
114115

@@ -128,7 +129,7 @@ async def league(self, ctx, decider: str, decider2: str = None):
128129
embed.set_footer(text=ctx.message.author.name, icon_url=ctx.message.author.avatar_url)
129130
embed.set_author(name=self.bot.user.name, icon_url=self.bot.user.avatar_url)
130131
item_list_message = await ctx.send(content=None, embed=embed)
131-
if page + 2 <= 1 or page + 2 < len(pagination):
132+
if page + 1 <= 1 or page + 1 < len(pagination):
132133
await item_list_message.add_reaction("➡")
133134
await item_list_message.add_reaction("❌")
134135

@@ -148,7 +149,7 @@ async def league(self, ctx, decider: str, decider2: str = None):
148149
embed.set_footer(text=ctx.message.author.name, icon_url=ctx.message.author.avatar_url)
149150
embed.set_author(name=self.bot.user.name, icon_url=self.bot.user.avatar_url)
150151
rune_list_message = await ctx.send(content=None, embed=embed)
151-
if page + 2 <= 1 or page + 2 < len(pagination):
152+
if page + 1 <= 1 or page + 1 < len(pagination):
152153
await rune_list_message.add_reaction("➡")
153154
await rune_list_message.add_reaction("❌")
154155

0 commit comments

Comments
 (0)