From 95b285bcd07b8e4130ac348cf421a9326f6968cd Mon Sep 17 00:00:00 2001 From: Fadi Atamny Date: Sun, 3 May 2020 12:13:58 +0300 Subject: [PATCH 01/18] added few commands and restrictions for them moved the functions to be static methods and sorted some other things out. --- welcomeCog/__init__.py | 2 +- welcomeCog/welcome.py | 197 ++++++++++++++++++++++++++++++++--------- 2 files changed, 155 insertions(+), 44 deletions(-) diff --git a/welcomeCog/__init__.py b/welcomeCog/__init__.py index f24b4db..318f347 100644 --- a/welcomeCog/__init__.py +++ b/welcomeCog/__init__.py @@ -2,4 +2,4 @@ from .welcome import WelcomeCog from redbot.core.bot import Red def setup(bot: Red): - bot.add_cog(WelcomeCog()) \ No newline at end of file + bot.add_cog(WelcomeCog(bot)) \ No newline at end of file diff --git a/welcomeCog/welcome.py b/welcomeCog/welcome.py index 1d1bcec..12b1b7f 100644 --- a/welcomeCog/welcome.py +++ b/welcomeCog/welcome.py @@ -9,68 +9,179 @@ from redbot.core.utils.chat_formatting import box, humanize_list, pagify url = 'https://raw.githubusercontent.com/Kanium/KaniumCogs/master/welcomeCog/data/embedded_message.json' allowed_guilds = {274657393936302080, 693796372092289024, 508781789737648138} - - -async def fetchMessage(): - async def fetch(): - async with aiohttp.ClientSession() as session: - async with session.get(url) as response: - html = await response.text() - x = json.loads(str(html)) - return x - return await fetch() - - -def formatMessage(jsonFormat): - try: - message = discord.Embed(title=str(jsonFormat['title']), description=''.join( - map(str, jsonFormat['description'])), color=int(jsonFormat['color'], 16)) - message.set_thumbnail(url=jsonFormat['thumbnail']) - for field in jsonFormat['fields']: - if(field['id'] != 'links'): - message.add_field( - name=field['name'], value=field['value'], inline=field['inline']) - else: - message.add_field(name=field['name'], value=''.join( - map(str, field['value'])), inline=field['inline']) - - message.set_footer( - text=jsonFormat['footer']['text'], icon_url=jsonFormat['footer']['icon_url']) - return message - - except: - message = discord.Embed(title="Kanium", description='', color=0x3399ff) - message.add_field( - name="Welcome", value='Welcome To Kanium !', inline=True) - return message +admin_roles = {'Developer', 'admin', 'Council'} class WelcomeCog(commands.Cog): - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - self.message = '' + + def __init__(self, bot): + self.bot = bot + self.message: str = '' + self.channel: discord.TextChannel = None + self.dailyJoinedCount: int = 0 + self.totalJoinedCount: int = 0 + self.dailyLeftCount: int = 0 + self.totalLeftCount: int = 0 + self.totalLogs: int = 0 + self.toggleLogs: bool = True + self.bot.loop.create_task(WelcomeCog.countReset(self)) + + @staticmethod + async def countReset(obj): + while True: + obj.dailyJoinedCount = 0 + obj.dailyLeftCount = 0 + await asyncio.sleep(86400) + + @staticmethod + async def fetchMessage(): + async def fetch(): + async with aiohttp.ClientSession() as session: + async with session.get(url) as response: + html = await response.text() + x = json.loads(str(html)) + return x + return await fetch() + + @staticmethod + def formatMessage(jsonFormat: str): + try: + message = discord.Embed(title=str(jsonFormat['title']), description=''.join( + map(str, jsonFormat['description'])), color=int(jsonFormat['color'], 16)) + message.set_thumbnail(url=jsonFormat['thumbnail']) + for field in jsonFormat['fields']: + if(field['id'] != 'links'): + message.add_field( + name=field['name'], value=field['value'], inline=field['inline']) + else: + message.add_field(name=field['name'], value=''.join( + map(str, field['value'])), inline=field['inline']) + + message.set_footer( + text=jsonFormat['footer']['text'], icon_url=jsonFormat['footer']['icon_url']) + return message + + except: + message = discord.Embed( + title='Kanium', description='', color=0x3399ff) + message.add_field( + name="Welcome", value='Welcome To Kanium !', inline=True) + return message + + @commands.command(name='pullmessage', description='pulls the message from github again') + @commands.has_any_role(*admin_roles) + async def pullMessage(self, ctx: commands.Context) -> None: + try: + await ctx.trigger_typing() + self.message = await WelcomeCog.fetchMessage() + await ctx.send('Welcome message updated') + except: + print('error occured fetching message') @commands.command(name='welcomepreview', case_insensitive=True, description='Shows a preview of the welcome message') - async def previewMessage(self, ctx): + @commands.has_any_role(*admin_roles) + async def previewMessage(self, ctx: commands.Context) -> None: try: + await ctx.trigger_typing() if ctx.guild.id not in allowed_guilds: return if self.message == '': - self.message = await fetchMessage() - message = formatMessage(self.message) + self.message = await WelcomeCog.fetchMessage() + message = WelcomeCog.formatMessage(self.message) await ctx.send(content=None, embed=message) except(): print(f'Error Occured!') + @commands.command(name='channel', description='Sets the channel to sends log to') + @commands.has_any_role(*admin_roles) + async def logChannel(self, ctx: commands.Context, channel: discord.TextChannel) -> None: + await ctx.trigger_typing() + + if not channel in ctx.guild.channels: + await ctx.send('Channel doesnt exist in guild') + return + + if not channel.permissions_for(ctx.guild.me).send_messages: + await ctx.send('No permissions to talk in that channel.') + return + + self.channel = channel + + await ctx.send(f'I will now send event notices to {channel.mention}.') + + @commands.command(name='stats', description='Shows current statistics') + @commands.has_any_role(*admin_roles) + async def statistics(self, ctx: commands.Context) -> None: + await ctx.trigger_typing() + + message = '```py\nDaily Joined = {0}\tDaily Left = {1}\nTotal Joined = {2}\tTotal Left = {3}\n------------------------\nTotal Logs = {4}```'.format( + self.dailyJoinedCount, self.dailyLeftCount, self.totalJoinedCount, self.totalLeftCount, self.totalLogs) + + await ctx.send(message) + + @commands.command(name='resetstats', description='Resets statistics') + @commands.has_any_role(*admin_roles) + async def resetStatistics(self, ctx: commands.Context) -> None: + await ctx.trigger_typing() + + self.dailyJoinedCount = 0 + self.dailyLeftCount = 0 + self.totalJoinedCount = 0 + self.totalLeftCount = 0 + self.totalLogs = 0 + + await ctx.send('Successfully reset the statistics') + @commands.Cog.listener() - async def on_member_join(self, member: discord.Member): + async def on_member_join(self, member: discord.Member) -> None: try: if member.guild.id not in allowed_guilds: return if self.message == '': - self.message = await fetchMessage() - message = formatMessage(self.message) + self.message = await WelcomeCog.fetchMessage() + message = WelcomeCog.formatMessage(self.message) await member.send(content=None, embed=message) + if self.channel in member.guild.channels and self.toggleLogs: + await self.channel.send('{0} - has joined the server'.format(member)) + self.totalJoinedCount += 1 + self.dailyJoinedCount += 1 + self.totalLogs += 1 except (discord.NotFound, discord.Forbidden): print( f'Error Occured! sending a dm to {member.display_name} didnt work !') + + @commands.Cog.listener() + async def on_member_remove(self, member: discord.Member) -> None: + try: + if self.channel in member.guild.channels and self.toggleLogs: + await self.channel.send('{0} - has left the server'.format(member)) + self.totalLeftCount += 1 + self.dailyLeftCount += 1 + self.totalLogs += 1 + except (discord.NotFound, discord.Forbidden): + print( + f'Error Occured!') + + @commands.Cog.listener() + async def on_member_ban(self, guild: discord.Guild, member: discord.Member) -> None: + try: + if not self.channel in member.guild.channels: + print('{0} - has been banned from the server'.format(member)) + return + await self.channel.send('{0} - has been banned from the server'.format(member)) + self.totalLogs += 1 + except (discord.NotFound, discord.Forbidden): + print( + f'Error Occured!') + + @commands.Cog.listener() + async def on_member_ban(self, guild: discord.Guild, member: discord.Member) -> None: + try: + if not self.channel in member.guild.channels: + print('{0} - has been unbanned from the server'.format(member)) + return + await self.channel.send('{0} - has been unbanned from the server'.format(member)) + self.totalLogs += 1 + except (discord.NotFound, discord.Forbidden): + print( + f'Error Occured!') From 294bc8b3555ddf362b7bb95d99dde94aee12ff1a Mon Sep 17 00:00:00 2001 From: Fadi Atamny Date: Sun, 3 May 2020 12:16:36 +0300 Subject: [PATCH 02/18] updated the readme --- welcomeCog/README.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/welcomeCog/README.md b/welcomeCog/README.md index 9653586..79a86ea 100644 --- a/welcomeCog/README.md +++ b/welcomeCog/README.md @@ -1,5 +1,6 @@ # WelcomeCog -This is the Kanium community/guild welcome cog. it sends a DM to any new user that joins the Kanium discord with a [message](./data/embedded_message.json), which has been templated in a json format. Note: This is All the cog does, there are no commands to operate the cog (yet). +This is the Kanium community/guild welcome cog. it sends a DM to any new user that joins the Kanium discord with a [message](./data/embedded_message.json), which has been templated in a json format. +Furthermore, this cog allows the ability to monitor discord activity and log it into a specific channel using the specific commands. The tracking of the bot resets the daily statistics every 24 hours after the bot has been launched. # How to use: @@ -19,7 +20,17 @@ In order to use our cog you would need to install it onto your instance of [RedB 3. ```[PREFIX]load welcomeCog``` ### To update the Cog: +- ```[PREFIX]cog uninstall welcomeCog``` - ```[PREFIX]repo update [RepoName]``` +- ```[PREFIX]cog install [RepoName] welcomeCog``` +- ```[PREFIX]load welcomeCog``` + +### Commands +- ```[PREFIX]welcomepreview``` - sends in the chat a preview of the template message +- ```[PREFIX]pullmessage``` - allows you to pull the latest version of your message without restarting the bot +- ```[PREFIX]channel``` - allows you to select a channel in your discord to dump logs to +- ```[PREFIX]stats``` - prints the statistics that the cog has gathered. +- ```[PREFIX]resetstats``` - allows for a hard reset of the stats ### To modify the sent message: From 83bb0cdc6c9e186d622f4fc26b8cdb88bada08ff Mon Sep 17 00:00:00 2001 From: Fadi Atamny Date: Sun, 3 May 2020 13:22:50 +0300 Subject: [PATCH 03/18] added more functionalities --- welcomeCog/README.md | 29 +++++++++--------- welcomeCog/welcome.py | 68 +++++++++++++++++++++++++++++++------------ 2 files changed, 66 insertions(+), 31 deletions(-) diff --git a/welcomeCog/README.md b/welcomeCog/README.md index 79a86ea..6f0903d 100644 --- a/welcomeCog/README.md +++ b/welcomeCog/README.md @@ -11,26 +11,29 @@ In order to use our cog you would need to install it onto your instance of [RedB - Instance of [RedBot](https://github.com/Cog-Creators/Red-DiscordBot) - Downloader cog has to be loaded. to load: - ```[Prefix]load downloader``` + `[Prefix]load downloader` ## How to install & load: -1. ```[PREFIX]repo add [RepoName] https://github.com/Kanium/KaniumCogs [ActiveBranch (EX: Master)] ``` -2. ```[PREFIX]cog install [RepoName] welcomeCog``` -3. ```[PREFIX]load welcomeCog``` +1. `[PREFIX]repo add [RepoName] https://github.com/Kanium/KaniumCogs [ActiveBranch (EX: Master)] ` +2. `[PREFIX]cog install [RepoName] welcomeCog` +3. `[PREFIX]load welcomeCog` ### To update the Cog: -- ```[PREFIX]cog uninstall welcomeCog``` -- ```[PREFIX]repo update [RepoName]``` -- ```[PREFIX]cog install [RepoName] welcomeCog``` -- ```[PREFIX]load welcomeCog``` +- `[PREFIX]cog uninstall welcomeCog` +- `[PREFIX]repo update [RepoName]` +- `[PREFIX]cog install [RepoName] welcomeCog` +- `[PREFIX]load welcomeCog` ### Commands -- ```[PREFIX]welcomepreview``` - sends in the chat a preview of the template message -- ```[PREFIX]pullmessage``` - allows you to pull the latest version of your message without restarting the bot -- ```[PREFIX]channel``` - allows you to select a channel in your discord to dump logs to -- ```[PREFIX]stats``` - prints the statistics that the cog has gathered. -- ```[PREFIX]resetstats``` - allows for a hard reset of the stats +- `[PREFIX]welcomepreview` - sends in the chat a preview of the template message +- `[PREFIX]pullmessage` - allows you to pull the latest version of your message without restarting the bot +- `[PREFIX]channel` - allows you to select a channel in your discord to dump logs to +- `[PREFIX]stats` - prints the statistics that the cog has gathered. +- `[PREFIX]resetstats` - allows for a hard reset of the stats +- `[PREFIX]toggleLogs` - Toggles the logs functionality on or off +- `[PREFIX]stopScheduler` - Stops the daily reset scheduler +- `[PREFIX]startScheduler` - Starts the daily reset scheduler ### To modify the sent message: diff --git a/welcomeCog/welcome.py b/welcomeCog/welcome.py index 12b1b7f..f4b3e0b 100644 --- a/welcomeCog/welcome.py +++ b/welcomeCog/welcome.py @@ -24,14 +24,8 @@ class WelcomeCog(commands.Cog): self.totalLeftCount: int = 0 self.totalLogs: int = 0 self.toggleLogs: bool = True - self.bot.loop.create_task(WelcomeCog.countReset(self)) - - @staticmethod - async def countReset(obj): - while True: - obj.dailyJoinedCount = 0 - obj.dailyLeftCount = 0 - await asyncio.sleep(86400) + self.scheduler: bool = False + self.task = None @staticmethod async def fetchMessage(): @@ -68,6 +62,12 @@ class WelcomeCog(commands.Cog): name="Welcome", value='Welcome To Kanium !', inline=True) return message + async def countReset(self): + while True: + self.dailyJoinedCount = 0 + self.dailyLeftCount = 0 + await asyncio.sleep(86400) + @commands.command(name='pullmessage', description='pulls the message from github again') @commands.has_any_role(*admin_roles) async def pullMessage(self, ctx: commands.Context) -> None: @@ -132,6 +132,42 @@ class WelcomeCog(commands.Cog): await ctx.send('Successfully reset the statistics') + @commands.command(name='toggleLogs', description='Toggles the logs functionality on or off') + @commands.has_any_role(*admin_roles) + async def toggleLogs(self, ctx: commands.Context) -> None: + await ctx.trigger_typing() + self.toggleLogs = not self.toggleLogs + await ctx.send('Logging functionality is `ON`' if self.toggleLogs else 'Logging functionality is `OFF`') + + @commands.command(name='stopscheduler', description='Stops the daily reset scheduler') + @commands.has_any_role(*admin_roles) + async def stopScheduler(self, ctx: commands.Context) -> None: + await ctx.trigger_typing() + + if not self.scheduler: + await ctx.send('Scheduler is already `OFF`') + return + print('before', len(asyncio.all_tasks())) + self.scheduler = False + self.task.cancel() + self.task = None + print('after', len(asyncio.all_tasks())) + await ctx.send('Scheduler has been turned `OFF`') + + @commands.command(name='startscheduler', description='Starts the daily reset scheduler') + @commands.has_any_role(*admin_roles) + async def startScheduler(self, ctx: commands.Context) -> None: + await ctx.trigger_typing() + + if self.scheduler: + await ctx.send('Scheduler is already `ON`') + return + print('before', len(asyncio.all_tasks())) + self.scheduler = True + self.task = self.bot.loop.create_task(self.countReset()) + print('after', len(asyncio.all_tasks())) + await ctx.send('Scheduler has been turned `ON`') + @commands.Cog.listener() async def on_member_join(self, member: discord.Member) -> None: try: @@ -142,7 +178,7 @@ class WelcomeCog(commands.Cog): message = WelcomeCog.formatMessage(self.message) await member.send(content=None, embed=message) if self.channel in member.guild.channels and self.toggleLogs: - await self.channel.send('{0} - has joined the server'.format(member)) + await self.channel.send('>>> @{0} - has joined the server'.format(member)) self.totalJoinedCount += 1 self.dailyJoinedCount += 1 self.totalLogs += 1 @@ -154,7 +190,7 @@ class WelcomeCog(commands.Cog): async def on_member_remove(self, member: discord.Member) -> None: try: if self.channel in member.guild.channels and self.toggleLogs: - await self.channel.send('{0} - has left the server'.format(member)) + await self.channel.send('>>> @{0} - has left the server'.format(member)) self.totalLeftCount += 1 self.dailyLeftCount += 1 self.totalLogs += 1 @@ -165,10 +201,8 @@ class WelcomeCog(commands.Cog): @commands.Cog.listener() async def on_member_ban(self, guild: discord.Guild, member: discord.Member) -> None: try: - if not self.channel in member.guild.channels: - print('{0} - has been banned from the server'.format(member)) - return - await self.channel.send('{0} - has been banned from the server'.format(member)) + if self.channel in member.guild.channels and self.toggleLogs: + await self.channel.send('>>> @{0} - has been banned from the server'.format(member)) self.totalLogs += 1 except (discord.NotFound, discord.Forbidden): print( @@ -177,10 +211,8 @@ class WelcomeCog(commands.Cog): @commands.Cog.listener() async def on_member_ban(self, guild: discord.Guild, member: discord.Member) -> None: try: - if not self.channel in member.guild.channels: - print('{0} - has been unbanned from the server'.format(member)) - return - await self.channel.send('{0} - has been unbanned from the server'.format(member)) + if self.channel in member.guild.channels and self.toggleLogs: + await self.channel.send('>>> @{0} - has been unbanned from the server'.format(member)) self.totalLogs += 1 except (discord.NotFound, discord.Forbidden): print( From e226407be006d317fa34231a24f450a0a7860c03 Mon Sep 17 00:00:00 2001 From: Fadi Atamny Date: Sun, 3 May 2020 13:26:45 +0300 Subject: [PATCH 04/18] changed name of command --- welcomeCog/README.md | 2 +- welcomeCog/welcome.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/welcomeCog/README.md b/welcomeCog/README.md index 6f0903d..27d8dfd 100644 --- a/welcomeCog/README.md +++ b/welcomeCog/README.md @@ -28,7 +28,7 @@ In order to use our cog you would need to install it onto your instance of [RedB ### Commands - `[PREFIX]welcomepreview` - sends in the chat a preview of the template message - `[PREFIX]pullmessage` - allows you to pull the latest version of your message without restarting the bot -- `[PREFIX]channel` - allows you to select a channel in your discord to dump logs to +- `[PREFIX]setchannel` - allows you to select a channel in your discord to dump logs to - `[PREFIX]stats` - prints the statistics that the cog has gathered. - `[PREFIX]resetstats` - allows for a hard reset of the stats - `[PREFIX]toggleLogs` - Toggles the logs functionality on or off diff --git a/welcomeCog/welcome.py b/welcomeCog/welcome.py index f4b3e0b..c7dbb05 100644 --- a/welcomeCog/welcome.py +++ b/welcomeCog/welcome.py @@ -92,9 +92,9 @@ class WelcomeCog(commands.Cog): except(): print(f'Error Occured!') - @commands.command(name='channel', description='Sets the channel to sends log to') + @commands.command(name='setchannel', description='Sets the channel to sends log to') @commands.has_any_role(*admin_roles) - async def logChannel(self, ctx: commands.Context, channel: discord.TextChannel) -> None: + async def setChannel(self, ctx: commands.Context, channel: discord.TextChannel) -> None: await ctx.trigger_typing() if not channel in ctx.guild.channels: From 5ac23633f983886ad9a8cf4b6aa9ba581b077bee Mon Sep 17 00:00:00 2001 From: Fadi Atamny Date: Sun, 3 May 2020 13:28:20 +0300 Subject: [PATCH 05/18] removed debug logs --- welcomeCog/welcome.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/welcomeCog/welcome.py b/welcomeCog/welcome.py index c7dbb05..b5d8e3e 100644 --- a/welcomeCog/welcome.py +++ b/welcomeCog/welcome.py @@ -147,11 +147,9 @@ class WelcomeCog(commands.Cog): if not self.scheduler: await ctx.send('Scheduler is already `OFF`') return - print('before', len(asyncio.all_tasks())) self.scheduler = False self.task.cancel() self.task = None - print('after', len(asyncio.all_tasks())) await ctx.send('Scheduler has been turned `OFF`') @commands.command(name='startscheduler', description='Starts the daily reset scheduler') @@ -162,10 +160,8 @@ class WelcomeCog(commands.Cog): if self.scheduler: await ctx.send('Scheduler is already `ON`') return - print('before', len(asyncio.all_tasks())) self.scheduler = True self.task = self.bot.loop.create_task(self.countReset()) - print('after', len(asyncio.all_tasks())) await ctx.send('Scheduler has been turned `ON`') @commands.Cog.listener() From 89c9f00ccd8dc84eec6216ba1351ddb1501e5aef Mon Sep 17 00:00:00 2001 From: Fadi Atamny Date: Sun, 3 May 2020 13:31:01 +0300 Subject: [PATCH 06/18] changed to mentions --- welcomeCog/welcome.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/welcomeCog/welcome.py b/welcomeCog/welcome.py index b5d8e3e..49fcf39 100644 --- a/welcomeCog/welcome.py +++ b/welcomeCog/welcome.py @@ -174,7 +174,7 @@ class WelcomeCog(commands.Cog): message = WelcomeCog.formatMessage(self.message) await member.send(content=None, embed=message) if self.channel in member.guild.channels and self.toggleLogs: - await self.channel.send('>>> @{0} - has joined the server'.format(member)) + await self.channel.send('>>> {0} - has joined the server'.format(member.mention)) self.totalJoinedCount += 1 self.dailyJoinedCount += 1 self.totalLogs += 1 @@ -186,7 +186,7 @@ class WelcomeCog(commands.Cog): async def on_member_remove(self, member: discord.Member) -> None: try: if self.channel in member.guild.channels and self.toggleLogs: - await self.channel.send('>>> @{0} - has left the server'.format(member)) + await self.channel.send('>>> @{0} - has left the server'.format(member.mention)) self.totalLeftCount += 1 self.dailyLeftCount += 1 self.totalLogs += 1 @@ -198,7 +198,7 @@ class WelcomeCog(commands.Cog): async def on_member_ban(self, guild: discord.Guild, member: discord.Member) -> None: try: if self.channel in member.guild.channels and self.toggleLogs: - await self.channel.send('>>> @{0} - has been banned from the server'.format(member)) + await self.channel.send('>>> @{0} - has been banned from the server'.format(member.mention)) self.totalLogs += 1 except (discord.NotFound, discord.Forbidden): print( @@ -208,7 +208,7 @@ class WelcomeCog(commands.Cog): async def on_member_ban(self, guild: discord.Guild, member: discord.Member) -> None: try: if self.channel in member.guild.channels and self.toggleLogs: - await self.channel.send('>>> @{0} - has been unbanned from the server'.format(member)) + await self.channel.send('>>> @{0} - has been unbanned from the server'.format(member.mention)) self.totalLogs += 1 except (discord.NotFound, discord.Forbidden): print( From b105ee300b55aad9db071f6cb6d9f2ede4f31c19 Mon Sep 17 00:00:00 2001 From: Fadi Atamny Date: Sun, 3 May 2020 16:21:47 +0300 Subject: [PATCH 07/18] moved to mentions --- welcomeCog/welcome.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/welcomeCog/welcome.py b/welcomeCog/welcome.py index 49fcf39..357e6c9 100644 --- a/welcomeCog/welcome.py +++ b/welcomeCog/welcome.py @@ -186,7 +186,7 @@ class WelcomeCog(commands.Cog): async def on_member_remove(self, member: discord.Member) -> None: try: if self.channel in member.guild.channels and self.toggleLogs: - await self.channel.send('>>> @{0} - has left the server'.format(member.mention)) + await self.channel.send('>>> {0} - has left the server'.format(member.mention)) self.totalLeftCount += 1 self.dailyLeftCount += 1 self.totalLogs += 1 @@ -198,7 +198,7 @@ class WelcomeCog(commands.Cog): async def on_member_ban(self, guild: discord.Guild, member: discord.Member) -> None: try: if self.channel in member.guild.channels and self.toggleLogs: - await self.channel.send('>>> @{0} - has been banned from the server'.format(member.mention)) + await self.channel.send('>>> {0} - has been banned from the server'.format(member.mention)) self.totalLogs += 1 except (discord.NotFound, discord.Forbidden): print( @@ -208,7 +208,7 @@ class WelcomeCog(commands.Cog): async def on_member_ban(self, guild: discord.Guild, member: discord.Member) -> None: try: if self.channel in member.guild.channels and self.toggleLogs: - await self.channel.send('>>> @{0} - has been unbanned from the server'.format(member.mention)) + await self.channel.send('>>> {0} - has been unbanned from the server'.format(member.mention)) self.totalLogs += 1 except (discord.NotFound, discord.Forbidden): print( From e1869b95d0b14f440eb73aca2527a4e670030b07 Mon Sep 17 00:00:00 2001 From: Fadi Atamny Date: Sun, 3 May 2020 16:25:52 +0300 Subject: [PATCH 08/18] fixed text --- welcomeCog/welcome.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/welcomeCog/welcome.py b/welcomeCog/welcome.py index 357e6c9..6f266cb 100644 --- a/welcomeCog/welcome.py +++ b/welcomeCog/welcome.py @@ -174,7 +174,7 @@ class WelcomeCog(commands.Cog): message = WelcomeCog.formatMessage(self.message) await member.send(content=None, embed=message) if self.channel in member.guild.channels and self.toggleLogs: - await self.channel.send('>>> {0} - has joined the server'.format(member.mention)) + await self.channel.send('>>> {0} has joined the server'.format(member.mention)) self.totalJoinedCount += 1 self.dailyJoinedCount += 1 self.totalLogs += 1 @@ -186,7 +186,7 @@ class WelcomeCog(commands.Cog): async def on_member_remove(self, member: discord.Member) -> None: try: if self.channel in member.guild.channels and self.toggleLogs: - await self.channel.send('>>> {0} - has left the server'.format(member.mention)) + await self.channel.send('>>> {0} has left the server'.format(member.mention)) self.totalLeftCount += 1 self.dailyLeftCount += 1 self.totalLogs += 1 @@ -198,7 +198,7 @@ class WelcomeCog(commands.Cog): async def on_member_ban(self, guild: discord.Guild, member: discord.Member) -> None: try: if self.channel in member.guild.channels and self.toggleLogs: - await self.channel.send('>>> {0} - has been banned from the server'.format(member.mention)) + await self.channel.send('>>> {0} has been banned from the server'.format(member.mention)) self.totalLogs += 1 except (discord.NotFound, discord.Forbidden): print( @@ -208,7 +208,7 @@ class WelcomeCog(commands.Cog): async def on_member_ban(self, guild: discord.Guild, member: discord.Member) -> None: try: if self.channel in member.guild.channels and self.toggleLogs: - await self.channel.send('>>> {0} - has been unbanned from the server'.format(member.mention)) + await self.channel.send('>>> {0} has been unbanned from the server'.format(member.mention)) self.totalLogs += 1 except (discord.NotFound, discord.Forbidden): print( From c685e7cf4a8e20a6a0483185dfe2fbdc4487db55 Mon Sep 17 00:00:00 2001 From: Fadi Atamny Date: Sun, 3 May 2020 19:04:42 +0300 Subject: [PATCH 09/18] changed to a different date system and updated icons and message looks --- welcomeCog/README.md | 8 +---- welcomeCog/data/embedded_message.json | 2 +- welcomeCog/info.json | 2 +- welcomeCog/welcome.py | 52 ++++++++++----------------- 4 files changed, 21 insertions(+), 43 deletions(-) diff --git a/welcomeCog/README.md b/welcomeCog/README.md index 27d8dfd..bfcc802 100644 --- a/welcomeCog/README.md +++ b/welcomeCog/README.md @@ -1,20 +1,17 @@ # WelcomeCog This is the Kanium community/guild welcome cog. it sends a DM to any new user that joins the Kanium discord with a [message](./data/embedded_message.json), which has been templated in a json format. -Furthermore, this cog allows the ability to monitor discord activity and log it into a specific channel using the specific commands. The tracking of the bot resets the daily statistics every 24 hours after the bot has been launched. +Furthermore, this cog allows the ability to monitor discord activity and log it into a specific channel using the specific commands. # How to use: - In order to use our cog you would need to install it onto your instance of [RedBot](https://github.com/Cog-Creators/Red-DiscordBot). ## Requirments: - - Instance of [RedBot](https://github.com/Cog-Creators/Red-DiscordBot) - Downloader cog has to be loaded. to load: `[Prefix]load downloader` ## How to install & load: - 1. `[PREFIX]repo add [RepoName] https://github.com/Kanium/KaniumCogs [ActiveBranch (EX: Master)] ` 2. `[PREFIX]cog install [RepoName] welcomeCog` 3. `[PREFIX]load welcomeCog` @@ -32,11 +29,8 @@ In order to use our cog you would need to install it onto your instance of [RedB - `[PREFIX]stats` - prints the statistics that the cog has gathered. - `[PREFIX]resetstats` - allows for a hard reset of the stats - `[PREFIX]toggleLogs` - Toggles the logs functionality on or off -- `[PREFIX]stopScheduler` - Stops the daily reset scheduler -- `[PREFIX]startScheduler` - Starts the daily reset scheduler ### To modify the sent message: - If you would like to modify the message to your liking, you can either : - fork the bot. change the [message](./data/embedded_message.json) and [welcome.py](./welcome.py) line 9 to your repo. - fork the bot. update the [welcome.py](./welcome.py) line 9 to be directed to your message.json file that you like without having it hosted on github with your repo. diff --git a/welcomeCog/data/embedded_message.json b/welcomeCog/data/embedded_message.json index fe70d2f..09d0fb4 100644 --- a/welcomeCog/data/embedded_message.json +++ b/welcomeCog/data/embedded_message.json @@ -11,7 +11,7 @@ "show earnestness in the submitted application as well as in becoming part of the community." ], "color":"0x3399ff", - "thumbnail": "https://i.imgur.com/4TLdfDA.png", + "thumbnail": "https://www.kanium.org/machineroom/logomodern.png", "fields":[ {"id":"text", "name":"Apply for membership", "value":"!apply ", "inline":"True"}, {"id":"text", "name":"Description", "value":"If you are certain about joining, use this command to do so", "inline":"True"}, diff --git a/welcomeCog/info.json b/welcomeCog/info.json index 5094e8f..43ab182 100644 --- a/welcomeCog/info.json +++ b/welcomeCog/info.json @@ -6,7 +6,7 @@ "name": "Welcome", "short": "Sends a welcome dm thats written in a specific format to the users", "description": "Sends a welcome dm thats written in a specific format to the users", - "requirements": ["aiohttp"], + "requirements": ["aiohttp","datetime"], "tags": [ "welcome" ] diff --git a/welcomeCog/welcome.py b/welcomeCog/welcome.py index 6f266cb..c8112bb 100644 --- a/welcomeCog/welcome.py +++ b/welcomeCog/welcome.py @@ -2,6 +2,7 @@ import asyncio import aiohttp import discord import json +from datetime import datetime from redbot.core import Config, checks, commands from redbot.core.utils.chat_formatting import box, humanize_list, pagify @@ -10,7 +11,7 @@ url = 'https://raw.githubusercontent.com/Kanium/KaniumCogs/master/welcomeCog/dat allowed_guilds = {274657393936302080, 693796372092289024, 508781789737648138} admin_roles = {'Developer', 'admin', 'Council'} - +statsThumbnailUrl = 'https://www.kanium.org/machineroom/logomachine-small.png' class WelcomeCog(commands.Cog): @@ -24,8 +25,7 @@ class WelcomeCog(commands.Cog): self.totalLeftCount: int = 0 self.totalLogs: int = 0 self.toggleLogs: bool = True - self.scheduler: bool = False - self.task = None + self.date = datetime.now() @staticmethod async def fetchMessage(): @@ -59,14 +59,16 @@ class WelcomeCog(commands.Cog): message = discord.Embed( title='Kanium', description='', color=0x3399ff) message.add_field( - name="Welcome", value='Welcome To Kanium !', inline=True) + name='Welcome', value='Welcome To Kanium !', inline=True) return message - async def countReset(self): - while True: + def __checkClock(self): + currdate = self.date - datetime.now() + if currdate.day >= 0 : self.dailyJoinedCount = 0 self.dailyLeftCount = 0 - await asyncio.sleep(86400) + self.date = datetime.now() + @commands.command(name='pullmessage', description='pulls the message from github again') @commands.has_any_role(*admin_roles) @@ -112,12 +114,15 @@ class WelcomeCog(commands.Cog): @commands.command(name='stats', description='Shows current statistics') @commands.has_any_role(*admin_roles) async def statistics(self, ctx: commands.Context) -> None: + self.__checkClock() await ctx.trigger_typing() - message = '```py\nDaily Joined = {0}\tDaily Left = {1}\nTotal Joined = {2}\tTotal Left = {3}\n------------------------\nTotal Logs = {4}```'.format( + statsString = '\nDaily Joined = {0}\tDaily Left = {1}\nTotal Joined = {2}\tTotal Left = {3}\n------------------------\nTotal Logs = {4}'.format( self.dailyJoinedCount, self.dailyLeftCount, self.totalJoinedCount, self.totalLeftCount, self.totalLogs) - await ctx.send(message) + message = discord.Embed(title='Server Traffic Stats', description='Statistics on server activity\n\n'.join(statsString)) + message.set_thumbnail(url=statsThumbnailUrl) + await ctx.send(content=None, embed=message) @commands.command(name='resetstats', description='Resets statistics') @commands.has_any_role(*admin_roles) @@ -139,31 +144,6 @@ class WelcomeCog(commands.Cog): self.toggleLogs = not self.toggleLogs await ctx.send('Logging functionality is `ON`' if self.toggleLogs else 'Logging functionality is `OFF`') - @commands.command(name='stopscheduler', description='Stops the daily reset scheduler') - @commands.has_any_role(*admin_roles) - async def stopScheduler(self, ctx: commands.Context) -> None: - await ctx.trigger_typing() - - if not self.scheduler: - await ctx.send('Scheduler is already `OFF`') - return - self.scheduler = False - self.task.cancel() - self.task = None - await ctx.send('Scheduler has been turned `OFF`') - - @commands.command(name='startscheduler', description='Starts the daily reset scheduler') - @commands.has_any_role(*admin_roles) - async def startScheduler(self, ctx: commands.Context) -> None: - await ctx.trigger_typing() - - if self.scheduler: - await ctx.send('Scheduler is already `ON`') - return - self.scheduler = True - self.task = self.bot.loop.create_task(self.countReset()) - await ctx.send('Scheduler has been turned `ON`') - @commands.Cog.listener() async def on_member_join(self, member: discord.Member) -> None: try: @@ -173,6 +153,7 @@ class WelcomeCog(commands.Cog): self.message = await WelcomeCog.fetchMessage() message = WelcomeCog.formatMessage(self.message) await member.send(content=None, embed=message) + self.__checkClock() if self.channel in member.guild.channels and self.toggleLogs: await self.channel.send('>>> {0} has joined the server'.format(member.mention)) self.totalJoinedCount += 1 @@ -185,6 +166,7 @@ class WelcomeCog(commands.Cog): @commands.Cog.listener() async def on_member_remove(self, member: discord.Member) -> None: try: + self.__checkClock() if self.channel in member.guild.channels and self.toggleLogs: await self.channel.send('>>> {0} has left the server'.format(member.mention)) self.totalLeftCount += 1 @@ -197,6 +179,7 @@ class WelcomeCog(commands.Cog): @commands.Cog.listener() async def on_member_ban(self, guild: discord.Guild, member: discord.Member) -> None: try: + self.__checkClock() if self.channel in member.guild.channels and self.toggleLogs: await self.channel.send('>>> {0} has been banned from the server'.format(member.mention)) self.totalLogs += 1 @@ -207,6 +190,7 @@ class WelcomeCog(commands.Cog): @commands.Cog.listener() async def on_member_ban(self, guild: discord.Guild, member: discord.Member) -> None: try: + self.__checkClock() if self.channel in member.guild.channels and self.toggleLogs: await self.channel.send('>>> {0} has been unbanned from the server'.format(member.mention)) self.totalLogs += 1 From dd34e01c5764ca270b10ffa2b794426faf6b3853 Mon Sep 17 00:00:00 2001 From: Fadi Atamny Date: Sun, 3 May 2020 20:04:33 +0300 Subject: [PATCH 10/18] splitting into two cogs --- trafficTrackerCog/README.md | 36 +++++++++ trafficTrackerCog/__init__.py | 5 ++ trafficTrackerCog/info.json | 13 +++ trafficTrackerCog/trafficTrack.py | 129 ++++++++++++++++++++++++++++++ welcomeCog/info.json | 2 +- welcomeCog/welcome.py | 111 +------------------------ 6 files changed, 185 insertions(+), 111 deletions(-) create mode 100644 trafficTrackerCog/README.md create mode 100644 trafficTrackerCog/__init__.py create mode 100644 trafficTrackerCog/info.json create mode 100644 trafficTrackerCog/trafficTrack.py diff --git a/trafficTrackerCog/README.md b/trafficTrackerCog/README.md new file mode 100644 index 0000000..bfcc802 --- /dev/null +++ b/trafficTrackerCog/README.md @@ -0,0 +1,36 @@ +# WelcomeCog +This is the Kanium community/guild welcome cog. it sends a DM to any new user that joins the Kanium discord with a [message](./data/embedded_message.json), which has been templated in a json format. +Furthermore, this cog allows the ability to monitor discord activity and log it into a specific channel using the specific commands. + +# How to use: +In order to use our cog you would need to install it onto your instance of [RedBot](https://github.com/Cog-Creators/Red-DiscordBot). + + +## Requirments: +- Instance of [RedBot](https://github.com/Cog-Creators/Red-DiscordBot) +- Downloader cog has to be loaded. to load: + `[Prefix]load downloader` + +## How to install & load: +1. `[PREFIX]repo add [RepoName] https://github.com/Kanium/KaniumCogs [ActiveBranch (EX: Master)] ` +2. `[PREFIX]cog install [RepoName] welcomeCog` +3. `[PREFIX]load welcomeCog` + +### To update the Cog: +- `[PREFIX]cog uninstall welcomeCog` +- `[PREFIX]repo update [RepoName]` +- `[PREFIX]cog install [RepoName] welcomeCog` +- `[PREFIX]load welcomeCog` + +### Commands +- `[PREFIX]welcomepreview` - sends in the chat a preview of the template message +- `[PREFIX]pullmessage` - allows you to pull the latest version of your message without restarting the bot +- `[PREFIX]setchannel` - allows you to select a channel in your discord to dump logs to +- `[PREFIX]stats` - prints the statistics that the cog has gathered. +- `[PREFIX]resetstats` - allows for a hard reset of the stats +- `[PREFIX]toggleLogs` - Toggles the logs functionality on or off + +### To modify the sent message: +If you would like to modify the message to your liking, you can either : +- fork the bot. change the [message](./data/embedded_message.json) and [welcome.py](./welcome.py) line 9 to your repo. +- fork the bot. update the [welcome.py](./welcome.py) line 9 to be directed to your message.json file that you like without having it hosted on github with your repo. diff --git a/trafficTrackerCog/__init__.py b/trafficTrackerCog/__init__.py new file mode 100644 index 0000000..05799ea --- /dev/null +++ b/trafficTrackerCog/__init__.py @@ -0,0 +1,5 @@ +from .trafficTrack import TrafficTrack +from redbot.core.bot import Red + +def setup(bot: Red): + bot.add_cog(TrafficTrack(bot)) \ No newline at end of file diff --git a/trafficTrackerCog/info.json b/trafficTrackerCog/info.json new file mode 100644 index 0000000..60ab654 --- /dev/null +++ b/trafficTrackerCog/info.json @@ -0,0 +1,13 @@ +{ + "author": [ + "Deathblade" + ], + "install_msg": "May Kanuim broaden your horizons", + "name": "TrafficTracker", + "short": "Tracks daily activity on the server", + "description": "Tracks incoming and outgoing member activity on the server with daily resets", + "requirements": ["aiohttp","datetime"], + "tags": [ + "Traffic" + ] +} \ No newline at end of file diff --git a/trafficTrackerCog/trafficTrack.py b/trafficTrackerCog/trafficTrack.py new file mode 100644 index 0000000..5acb9cf --- /dev/null +++ b/trafficTrackerCog/trafficTrack.py @@ -0,0 +1,129 @@ +import discord +from datetime import datetime + +from redbot.core import Config, checks, commands +from redbot.core.utils.chat_formatting import box, humanize_list, pagify + +allowed_guilds = {274657393936302080, 693796372092289024, 508781789737648138} +admin_roles = {'Developer', 'admin', 'Council'} +statsThumbnailUrl = 'https://www.kanium.org/machineroom/logomachine-small.png' + +class TrafficTrack(commands.Cog): + + def __init__(self, bot): + self.channel: discord.TextChannel = None + self.dailyJoinedCount: int = 0 + self.totalJoinedCount: int = 0 + self.dailyLeftCount: int = 0 + self.totalLeftCount: int = 0 + self.totalLogs: int = 0 + self.toggleLogs: bool = True + self.date = datetime.now() + + def __checkClock(self): + currdate = self.date - datetime.now() + if currdate.days >= 0 : + self.dailyJoinedCount = 0 + self.dailyLeftCount = 0 + self.date = datetime.now() + + @commands.command(name='setchannel', description='Sets the channel to sends log to') + @commands.has_any_role(*admin_roles) + async def setChannel(self, ctx: commands.Context, channel: discord.TextChannel) -> None: + await ctx.trigger_typing() + + if not channel in ctx.guild.channels: + await ctx.send('Channel doesnt exist in guild') + return + + if not channel.permissions_for(ctx.guild.me).send_messages: + await ctx.send('No permissions to talk in that channel.') + return + + self.channel = channel + + await ctx.send(f'I will now send event notices to {channel.mention}.') + + @commands.command(name='stats', description='Shows current statistics') + @commands.has_any_role(*admin_roles) + async def statistics(self, ctx: commands.Context) -> None: + self.__checkClock() + await ctx.trigger_typing() + message = discord.Embed(title='Server Traffic Stats', description='Statistics on server activity\n\n') + message.set_thumbnail(url=statsThumbnailUrl) + message.add_field(name='Daily Joined', value=self.dailyJoinedCount, inline='True') + message.add_field(name='Daily Left', value='{0}\n'.format(self.dailyLeftCount), inline='True') + message.add_field(name='Total Joined', value=self.totalJoinedCount, inline='True') + message.add_field(name='Total Left', value=self.totalLeftCount, inline='True') + message.add_field(name='Total Traffic', value=self.totalLogs, inline='False') + await ctx.send(content=None, embed=message) + + @commands.command(name='resetstats', description='Resets statistics') + @commands.has_any_role(*admin_roles) + async def resetStatistics(self, ctx: commands.Context) -> None: + await ctx.trigger_typing() + + self.dailyJoinedCount = 0 + self.dailyLeftCount = 0 + self.totalJoinedCount = 0 + self.totalLeftCount = 0 + self.totalLogs = 0 + + await ctx.send('Successfully reset the statistics') + + @commands.command(name='toggleLogs', description='Toggles the logs functionality on or off') + @commands.has_any_role(*admin_roles) + async def toggleLogs(self, ctx: commands.Context) -> None: + await ctx.trigger_typing() + self.toggleLogs = not self.toggleLogs + await ctx.send('Logging functionality is `ON`' if self.toggleLogs else 'Logging functionality is `OFF`') + + @commands.Cog.listener() + async def on_member_join(self, member: discord.Member) -> None: + try: + if member.guild.id not in allowed_guilds: + return + self.__checkClock() + if self.channel in member.guild.channels and self.toggleLogs: + await self.channel.send('>>> {0} has joined the server'.format(member.mention)) + self.totalJoinedCount += 1 + self.dailyJoinedCount += 1 + self.totalLogs += 1 + except (discord.NotFound, discord.Forbidden): + print( + f'Error Occured! sending a dm to {member.display_name} didnt work !') + + @commands.Cog.listener() + async def on_member_remove(self, member: discord.Member) -> None: + try: + self.__checkClock() + if self.channel in member.guild.channels and self.toggleLogs: + await self.channel.send('>>> {0} has left the server'.format(member.mention)) + self.totalLeftCount += 1 + self.dailyLeftCount += 1 + self.totalLogs += 1 + except (discord.NotFound, discord.Forbidden): + print( + f'Error Occured!') + + @commands.Cog.listener() + async def on_member_ban(self, guild: discord.Guild, member: discord.Member) -> None: + try: + self.__checkClock() + if self.channel in member.guild.channels and self.toggleLogs: + await self.channel.send('>>> {0} has been banned from the server'.format(member.mention)) + self.totalLogs += 1 + except (discord.NotFound, discord.Forbidden): + print( + f'Error Occured!') + + @commands.Cog.listener() + async def on_member_ban(self, guild: discord.Guild, member: discord.Member) -> None: + try: + self.__checkClock() + if self.channel in member.guild.channels and self.toggleLogs: + await self.channel.send('>>> {0} has been unbanned from the server'.format(member.mention)) + self.totalLogs += 1 + except (discord.NotFound, discord.Forbidden): + print( + f'Error Occured!') diff --git a/welcomeCog/info.json b/welcomeCog/info.json index 43ab182..5094e8f 100644 --- a/welcomeCog/info.json +++ b/welcomeCog/info.json @@ -6,7 +6,7 @@ "name": "Welcome", "short": "Sends a welcome dm thats written in a specific format to the users", "description": "Sends a welcome dm thats written in a specific format to the users", - "requirements": ["aiohttp","datetime"], + "requirements": ["aiohttp"], "tags": [ "welcome" ] diff --git a/welcomeCog/welcome.py b/welcomeCog/welcome.py index c8112bb..35928ef 100644 --- a/welcomeCog/welcome.py +++ b/welcomeCog/welcome.py @@ -1,8 +1,6 @@ -import asyncio import aiohttp import discord import json -from datetime import datetime from redbot.core import Config, checks, commands from redbot.core.utils.chat_formatting import box, humanize_list, pagify @@ -11,21 +9,13 @@ url = 'https://raw.githubusercontent.com/Kanium/KaniumCogs/master/welcomeCog/dat allowed_guilds = {274657393936302080, 693796372092289024, 508781789737648138} admin_roles = {'Developer', 'admin', 'Council'} -statsThumbnailUrl = 'https://www.kanium.org/machineroom/logomachine-small.png' + class WelcomeCog(commands.Cog): def __init__(self, bot): self.bot = bot self.message: str = '' - self.channel: discord.TextChannel = None - self.dailyJoinedCount: int = 0 - self.totalJoinedCount: int = 0 - self.dailyLeftCount: int = 0 - self.totalLeftCount: int = 0 - self.totalLogs: int = 0 - self.toggleLogs: bool = True - self.date = datetime.now() @staticmethod async def fetchMessage(): @@ -62,14 +52,6 @@ class WelcomeCog(commands.Cog): name='Welcome', value='Welcome To Kanium !', inline=True) return message - def __checkClock(self): - currdate = self.date - datetime.now() - if currdate.day >= 0 : - self.dailyJoinedCount = 0 - self.dailyLeftCount = 0 - self.date = datetime.now() - - @commands.command(name='pullmessage', description='pulls the message from github again') @commands.has_any_role(*admin_roles) async def pullMessage(self, ctx: commands.Context) -> None: @@ -94,56 +76,6 @@ class WelcomeCog(commands.Cog): except(): print(f'Error Occured!') - @commands.command(name='setchannel', description='Sets the channel to sends log to') - @commands.has_any_role(*admin_roles) - async def setChannel(self, ctx: commands.Context, channel: discord.TextChannel) -> None: - await ctx.trigger_typing() - - if not channel in ctx.guild.channels: - await ctx.send('Channel doesnt exist in guild') - return - - if not channel.permissions_for(ctx.guild.me).send_messages: - await ctx.send('No permissions to talk in that channel.') - return - - self.channel = channel - - await ctx.send(f'I will now send event notices to {channel.mention}.') - - @commands.command(name='stats', description='Shows current statistics') - @commands.has_any_role(*admin_roles) - async def statistics(self, ctx: commands.Context) -> None: - self.__checkClock() - await ctx.trigger_typing() - - statsString = '\nDaily Joined = {0}\tDaily Left = {1}\nTotal Joined = {2}\tTotal Left = {3}\n------------------------\nTotal Logs = {4}'.format( - self.dailyJoinedCount, self.dailyLeftCount, self.totalJoinedCount, self.totalLeftCount, self.totalLogs) - - message = discord.Embed(title='Server Traffic Stats', description='Statistics on server activity\n\n'.join(statsString)) - message.set_thumbnail(url=statsThumbnailUrl) - await ctx.send(content=None, embed=message) - - @commands.command(name='resetstats', description='Resets statistics') - @commands.has_any_role(*admin_roles) - async def resetStatistics(self, ctx: commands.Context) -> None: - await ctx.trigger_typing() - - self.dailyJoinedCount = 0 - self.dailyLeftCount = 0 - self.totalJoinedCount = 0 - self.totalLeftCount = 0 - self.totalLogs = 0 - - await ctx.send('Successfully reset the statistics') - - @commands.command(name='toggleLogs', description='Toggles the logs functionality on or off') - @commands.has_any_role(*admin_roles) - async def toggleLogs(self, ctx: commands.Context) -> None: - await ctx.trigger_typing() - self.toggleLogs = not self.toggleLogs - await ctx.send('Logging functionality is `ON`' if self.toggleLogs else 'Logging functionality is `OFF`') - @commands.Cog.listener() async def on_member_join(self, member: discord.Member) -> None: try: @@ -153,47 +85,6 @@ class WelcomeCog(commands.Cog): self.message = await WelcomeCog.fetchMessage() message = WelcomeCog.formatMessage(self.message) await member.send(content=None, embed=message) - self.__checkClock() - if self.channel in member.guild.channels and self.toggleLogs: - await self.channel.send('>>> {0} has joined the server'.format(member.mention)) - self.totalJoinedCount += 1 - self.dailyJoinedCount += 1 - self.totalLogs += 1 except (discord.NotFound, discord.Forbidden): print( f'Error Occured! sending a dm to {member.display_name} didnt work !') - - @commands.Cog.listener() - async def on_member_remove(self, member: discord.Member) -> None: - try: - self.__checkClock() - if self.channel in member.guild.channels and self.toggleLogs: - await self.channel.send('>>> {0} has left the server'.format(member.mention)) - self.totalLeftCount += 1 - self.dailyLeftCount += 1 - self.totalLogs += 1 - except (discord.NotFound, discord.Forbidden): - print( - f'Error Occured!') - - @commands.Cog.listener() - async def on_member_ban(self, guild: discord.Guild, member: discord.Member) -> None: - try: - self.__checkClock() - if self.channel in member.guild.channels and self.toggleLogs: - await self.channel.send('>>> {0} has been banned from the server'.format(member.mention)) - self.totalLogs += 1 - except (discord.NotFound, discord.Forbidden): - print( - f'Error Occured!') - - @commands.Cog.listener() - async def on_member_ban(self, guild: discord.Guild, member: discord.Member) -> None: - try: - self.__checkClock() - if self.channel in member.guild.channels and self.toggleLogs: - await self.channel.send('>>> {0} has been unbanned from the server'.format(member.mention)) - self.totalLogs += 1 - except (discord.NotFound, discord.Forbidden): - print( - f'Error Occured!') From 75d092f2d7b995d83a4a32ebb6466a3375d23890 Mon Sep 17 00:00:00 2001 From: Fadi Atamny Date: Sun, 3 May 2020 20:07:03 +0300 Subject: [PATCH 11/18] updated readmes --- trafficTrackerCog/README.md | 22 +++++++--------------- trafficTrackerCog/info.json | 2 +- welcomeCog/README.md | 4 ---- 3 files changed, 8 insertions(+), 20 deletions(-) diff --git a/trafficTrackerCog/README.md b/trafficTrackerCog/README.md index bfcc802..085ebba 100644 --- a/trafficTrackerCog/README.md +++ b/trafficTrackerCog/README.md @@ -1,6 +1,5 @@ -# WelcomeCog -This is the Kanium community/guild welcome cog. it sends a DM to any new user that joins the Kanium discord with a [message](./data/embedded_message.json), which has been templated in a json format. -Furthermore, this cog allows the ability to monitor discord activity and log it into a specific channel using the specific commands. +# TrafficTrackerCog +This is the Kanium community/guild welcome cog. monitors the server for activity and logs them to a specific channel using the specific commands. # How to use: In order to use our cog you would need to install it onto your instance of [RedBot](https://github.com/Cog-Creators/Red-DiscordBot). @@ -13,24 +12,17 @@ In order to use our cog you would need to install it onto your instance of [RedB ## How to install & load: 1. `[PREFIX]repo add [RepoName] https://github.com/Kanium/KaniumCogs [ActiveBranch (EX: Master)] ` -2. `[PREFIX]cog install [RepoName] welcomeCog` -3. `[PREFIX]load welcomeCog` +2. `[PREFIX]cog install [RepoName] trafficTrackerCog` +3. `[PREFIX]load trafficTrackerCog` ### To update the Cog: -- `[PREFIX]cog uninstall welcomeCog` +- `[PREFIX]cog uninstall trafficTrackerCog` - `[PREFIX]repo update [RepoName]` -- `[PREFIX]cog install [RepoName] welcomeCog` -- `[PREFIX]load welcomeCog` +- `[PREFIX]cog install [RepoName] trafficTrackerCog` +- `[PREFIX]load trafficTrackerCog` ### Commands -- `[PREFIX]welcomepreview` - sends in the chat a preview of the template message -- `[PREFIX]pullmessage` - allows you to pull the latest version of your message without restarting the bot - `[PREFIX]setchannel` - allows you to select a channel in your discord to dump logs to - `[PREFIX]stats` - prints the statistics that the cog has gathered. - `[PREFIX]resetstats` - allows for a hard reset of the stats - `[PREFIX]toggleLogs` - Toggles the logs functionality on or off - -### To modify the sent message: -If you would like to modify the message to your liking, you can either : -- fork the bot. change the [message](./data/embedded_message.json) and [welcome.py](./welcome.py) line 9 to your repo. -- fork the bot. update the [welcome.py](./welcome.py) line 9 to be directed to your message.json file that you like without having it hosted on github with your repo. diff --git a/trafficTrackerCog/info.json b/trafficTrackerCog/info.json index 60ab654..c84f72f 100644 --- a/trafficTrackerCog/info.json +++ b/trafficTrackerCog/info.json @@ -6,7 +6,7 @@ "name": "TrafficTracker", "short": "Tracks daily activity on the server", "description": "Tracks incoming and outgoing member activity on the server with daily resets", - "requirements": ["aiohttp","datetime"], + "requirements": ["datetime"], "tags": [ "Traffic" ] diff --git a/welcomeCog/README.md b/welcomeCog/README.md index bfcc802..ad81d7b 100644 --- a/welcomeCog/README.md +++ b/welcomeCog/README.md @@ -25,10 +25,6 @@ In order to use our cog you would need to install it onto your instance of [RedB ### Commands - `[PREFIX]welcomepreview` - sends in the chat a preview of the template message - `[PREFIX]pullmessage` - allows you to pull the latest version of your message without restarting the bot -- `[PREFIX]setchannel` - allows you to select a channel in your discord to dump logs to -- `[PREFIX]stats` - prints the statistics that the cog has gathered. -- `[PREFIX]resetstats` - allows for a hard reset of the stats -- `[PREFIX]toggleLogs` - Toggles the logs functionality on or off ### To modify the sent message: If you would like to modify the message to your liking, you can either : From a5ed8fe54062cdddb632a7d5c0b5040ddd914a7d Mon Sep 17 00:00:00 2001 From: Fadi Atamny Date: Sun, 3 May 2020 20:11:37 +0300 Subject: [PATCH 12/18] fixed names --- trafficTrackerCog/{trafficTrack.py => TrafficTracker.py} | 7 ++++--- trafficTrackerCog/__init__.py | 4 ++-- welcomeCog/welcome.py | 3 +-- 3 files changed, 7 insertions(+), 7 deletions(-) rename trafficTrackerCog/{trafficTrack.py => TrafficTracker.py} (97%) diff --git a/trafficTrackerCog/trafficTrack.py b/trafficTrackerCog/TrafficTracker.py similarity index 97% rename from trafficTrackerCog/trafficTrack.py rename to trafficTrackerCog/TrafficTracker.py index 5acb9cf..d30872f 100644 --- a/trafficTrackerCog/trafficTrack.py +++ b/trafficTrackerCog/TrafficTracker.py @@ -1,8 +1,7 @@ import discord from datetime import datetime -from redbot.core import Config, checks, commands -from redbot.core.utils.chat_formatting import box, humanize_list, pagify +from redbot.core import Config, commands allowed_guilds = {274657393936302080, 693796372092289024, 508781789737648138} admin_roles = {'Developer', 'admin', 'Council'} @@ -53,9 +52,9 @@ class TrafficTrack(commands.Cog): message.set_thumbnail(url=statsThumbnailUrl) message.add_field(name='Daily Joined', value=self.dailyJoinedCount, inline='True') message.add_field(name='Daily Left', value='{0}\n'.format(self.dailyLeftCount), inline='True') + message.add_field(name='Total Traffic', value=self.totalLogs, inline='False') message.add_field(name='Total Joined', value=self.totalJoinedCount, inline='True') message.add_field(name='Total Left', value=self.totalLeftCount, inline='True') - message.add_field(name='Total Traffic', value=self.totalLogs, inline='False') await ctx.send(content=None, embed=message) @commands.command(name='resetstats', description='Resets statistics') @@ -112,6 +111,8 @@ class TrafficTrack(commands.Cog): self.__checkClock() if self.channel in member.guild.channels and self.toggleLogs: await self.channel.send('>>> {0} has been banned from the server'.format(member.mention)) + self.totalLeftCount += 1 + self.dailyLeftCount += 1 self.totalLogs += 1 except (discord.NotFound, discord.Forbidden): print( diff --git a/trafficTrackerCog/__init__.py b/trafficTrackerCog/__init__.py index 05799ea..d3c1335 100644 --- a/trafficTrackerCog/__init__.py +++ b/trafficTrackerCog/__init__.py @@ -1,5 +1,5 @@ -from .trafficTrack import TrafficTrack +from .TrafficTracker import TrafficTracker from redbot.core.bot import Red def setup(bot: Red): - bot.add_cog(TrafficTrack(bot)) \ No newline at end of file + bot.add_cog(TrafficTracker(bot)) \ No newline at end of file diff --git a/welcomeCog/welcome.py b/welcomeCog/welcome.py index 35928ef..abfe94a 100644 --- a/welcomeCog/welcome.py +++ b/welcomeCog/welcome.py @@ -2,8 +2,7 @@ import aiohttp import discord import json -from redbot.core import Config, checks, commands -from redbot.core.utils.chat_formatting import box, humanize_list, pagify +from redbot.core import Config, commands url = 'https://raw.githubusercontent.com/Kanium/KaniumCogs/master/welcomeCog/data/embedded_message.json' From a4d71b5f6b6ea5a700e3c78fe7ded0110baf76a3 Mon Sep 17 00:00:00 2001 From: Fadi Atamny Date: Sun, 3 May 2020 20:13:41 +0300 Subject: [PATCH 13/18] miss spelling --- trafficTrackerCog/info.json | 2 +- welcomeCog/info.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/trafficTrackerCog/info.json b/trafficTrackerCog/info.json index c84f72f..407cdaa 100644 --- a/trafficTrackerCog/info.json +++ b/trafficTrackerCog/info.json @@ -2,7 +2,7 @@ "author": [ "Deathblade" ], - "install_msg": "May Kanuim broaden your horizons", + "install_msg": "May Kanium broaden your horizons", "name": "TrafficTracker", "short": "Tracks daily activity on the server", "description": "Tracks incoming and outgoing member activity on the server with daily resets", diff --git a/welcomeCog/info.json b/welcomeCog/info.json index 5094e8f..66d0f2d 100644 --- a/welcomeCog/info.json +++ b/welcomeCog/info.json @@ -2,7 +2,7 @@ "author": [ "Deathblade" ], - "install_msg": "May Kanuim show you the way", + "install_msg": "May Kanium show you the way", "name": "Welcome", "short": "Sends a welcome dm thats written in a specific format to the users", "description": "Sends a welcome dm thats written in a specific format to the users", From 288cb0efa41484660042009feceb10ee01d9d529 Mon Sep 17 00:00:00 2001 From: Fadi Atamny Date: Sun, 3 May 2020 20:14:46 +0300 Subject: [PATCH 14/18] naming --- trafficTrackerCog/TrafficTracker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trafficTrackerCog/TrafficTracker.py b/trafficTrackerCog/TrafficTracker.py index d30872f..633cd94 100644 --- a/trafficTrackerCog/TrafficTracker.py +++ b/trafficTrackerCog/TrafficTracker.py @@ -7,7 +7,7 @@ allowed_guilds = {274657393936302080, 693796372092289024, 508781789737648138} admin_roles = {'Developer', 'admin', 'Council'} statsThumbnailUrl = 'https://www.kanium.org/machineroom/logomachine-small.png' -class TrafficTrack(commands.Cog): +class TrafficTracker(commands.Cog): def __init__(self, bot): self.channel: discord.TextChannel = None From 87a8c5916240166ed8f7ab7b8525b5983707037d Mon Sep 17 00:00:00 2001 From: Fadi Atamny Date: Sun, 3 May 2020 20:18:24 +0300 Subject: [PATCH 15/18] changed name of method --- trafficTrackerCog/README.md | 2 +- trafficTrackerCog/TrafficTracker.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/trafficTrackerCog/README.md b/trafficTrackerCog/README.md index 085ebba..fbf3f26 100644 --- a/trafficTrackerCog/README.md +++ b/trafficTrackerCog/README.md @@ -22,7 +22,7 @@ In order to use our cog you would need to install it onto your instance of [RedB - `[PREFIX]load trafficTrackerCog` ### Commands -- `[PREFIX]setchannel` - allows you to select a channel in your discord to dump logs to +- `[PREFIX]settrafficchannel` - allows you to select a channel in your discord to dump logs to - `[PREFIX]stats` - prints the statistics that the cog has gathered. - `[PREFIX]resetstats` - allows for a hard reset of the stats - `[PREFIX]toggleLogs` - Toggles the logs functionality on or off diff --git a/trafficTrackerCog/TrafficTracker.py b/trafficTrackerCog/TrafficTracker.py index 633cd94..35a4667 100644 --- a/trafficTrackerCog/TrafficTracker.py +++ b/trafficTrackerCog/TrafficTracker.py @@ -26,9 +26,9 @@ class TrafficTracker(commands.Cog): self.dailyLeftCount = 0 self.date = datetime.now() - @commands.command(name='setchannel', description='Sets the channel to sends log to') + @commands.command(name='settrafficchannel', description='Sets the channel to sends log to') @commands.has_any_role(*admin_roles) - async def setChannel(self, ctx: commands.Context, channel: discord.TextChannel) -> None: + async def setTrafficChannel(self, ctx: commands.Context, channel: discord.TextChannel) -> None: await ctx.trigger_typing() if not channel in ctx.guild.channels: From d8d425e6c3a14a70b453c365e255f9dcbe8006b6 Mon Sep 17 00:00:00 2001 From: Fadi Atamny Date: Sun, 3 May 2020 20:21:43 +0300 Subject: [PATCH 16/18] updated readme --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4d5ce1c..c676ac1 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,5 @@ cogs made for our Royal butt. ## Our Cogs: -- [WelcomeCog](./welcomeCog) \ No newline at end of file +- [WelcomeCog](./welcomeCog) +- [TrafficTrackerCog](./trafficTrackerCog) \ No newline at end of file From 033736e3cf1f40051bd90d44fe15adf044ad40b0 Mon Sep 17 00:00:00 2001 From: Fadi Atamny Date: Sun, 3 May 2020 20:27:49 +0300 Subject: [PATCH 17/18] changed the name to something reasonable --- README.md | 2 +- {trafficTrackerCog => trafficCog}/README.md | 12 ++++++------ trafficCog/__init__.py | 5 +++++ {trafficTrackerCog => trafficCog}/info.json | 2 +- .../TrafficTracker.py => trafficCog/trafficCog.py | 2 +- trafficTrackerCog/__init__.py | 5 ----- 6 files changed, 14 insertions(+), 14 deletions(-) rename {trafficTrackerCog => trafficCog}/README.md (79%) create mode 100644 trafficCog/__init__.py rename {trafficTrackerCog => trafficCog}/info.json (91%) rename trafficTrackerCog/TrafficTracker.py => trafficCog/trafficCog.py (99%) delete mode 100644 trafficTrackerCog/__init__.py diff --git a/README.md b/README.md index c676ac1..9a9d71a 100644 --- a/README.md +++ b/README.md @@ -3,4 +3,4 @@ ## Our Cogs: - [WelcomeCog](./welcomeCog) -- [TrafficTrackerCog](./trafficTrackerCog) \ No newline at end of file +- [TrafficCog](./trafficCog) \ No newline at end of file diff --git a/trafficTrackerCog/README.md b/trafficCog/README.md similarity index 79% rename from trafficTrackerCog/README.md rename to trafficCog/README.md index fbf3f26..03a466a 100644 --- a/trafficTrackerCog/README.md +++ b/trafficCog/README.md @@ -1,4 +1,4 @@ -# TrafficTrackerCog +# TrafficCog This is the Kanium community/guild welcome cog. monitors the server for activity and logs them to a specific channel using the specific commands. # How to use: @@ -12,14 +12,14 @@ In order to use our cog you would need to install it onto your instance of [RedB ## How to install & load: 1. `[PREFIX]repo add [RepoName] https://github.com/Kanium/KaniumCogs [ActiveBranch (EX: Master)] ` -2. `[PREFIX]cog install [RepoName] trafficTrackerCog` -3. `[PREFIX]load trafficTrackerCog` +2. `[PREFIX]cog install [RepoName] trafficCog` +3. `[PREFIX]load trafficCog` ### To update the Cog: -- `[PREFIX]cog uninstall trafficTrackerCog` +- `[PREFIX]cog uninstall trafficCog` - `[PREFIX]repo update [RepoName]` -- `[PREFIX]cog install [RepoName] trafficTrackerCog` -- `[PREFIX]load trafficTrackerCog` +- `[PREFIX]cog install [RepoName] trafficCog` +- `[PREFIX]load trafficCog` ### Commands - `[PREFIX]settrafficchannel` - allows you to select a channel in your discord to dump logs to diff --git a/trafficCog/__init__.py b/trafficCog/__init__.py new file mode 100644 index 0000000..ddc351e --- /dev/null +++ b/trafficCog/__init__.py @@ -0,0 +1,5 @@ +from .trafficCog import TrafficCog +from redbot.core.bot import Red + +def setup(bot: Red): + bot.add_cog(TrafficCog(bot)) \ No newline at end of file diff --git a/trafficTrackerCog/info.json b/trafficCog/info.json similarity index 91% rename from trafficTrackerCog/info.json rename to trafficCog/info.json index 407cdaa..6fd6fa5 100644 --- a/trafficTrackerCog/info.json +++ b/trafficCog/info.json @@ -3,7 +3,7 @@ "Deathblade" ], "install_msg": "May Kanium broaden your horizons", - "name": "TrafficTracker", + "name": "TrafficCog", "short": "Tracks daily activity on the server", "description": "Tracks incoming and outgoing member activity on the server with daily resets", "requirements": ["datetime"], diff --git a/trafficTrackerCog/TrafficTracker.py b/trafficCog/trafficCog.py similarity index 99% rename from trafficTrackerCog/TrafficTracker.py rename to trafficCog/trafficCog.py index 35a4667..60d7107 100644 --- a/trafficTrackerCog/TrafficTracker.py +++ b/trafficCog/trafficCog.py @@ -7,7 +7,7 @@ allowed_guilds = {274657393936302080, 693796372092289024, 508781789737648138} admin_roles = {'Developer', 'admin', 'Council'} statsThumbnailUrl = 'https://www.kanium.org/machineroom/logomachine-small.png' -class TrafficTracker(commands.Cog): +class TrafficCog(commands.Cog): def __init__(self, bot): self.channel: discord.TextChannel = None diff --git a/trafficTrackerCog/__init__.py b/trafficTrackerCog/__init__.py deleted file mode 100644 index d3c1335..0000000 --- a/trafficTrackerCog/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -from .TrafficTracker import TrafficTracker -from redbot.core.bot import Red - -def setup(bot: Red): - bot.add_cog(TrafficTracker(bot)) \ No newline at end of file From 9dd4ccb25d66101230e4a3f05368b4e097375b92 Mon Sep 17 00:00:00 2001 From: Fadi Atamny Date: Sun, 3 May 2020 20:40:57 +0300 Subject: [PATCH 18/18] coloooorzzzz --- trafficCog/trafficCog.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trafficCog/trafficCog.py b/trafficCog/trafficCog.py index 60d7107..1de07a8 100644 --- a/trafficCog/trafficCog.py +++ b/trafficCog/trafficCog.py @@ -48,7 +48,7 @@ class TrafficCog(commands.Cog): async def statistics(self, ctx: commands.Context) -> None: self.__checkClock() await ctx.trigger_typing() - message = discord.Embed(title='Server Traffic Stats', description='Statistics on server activity\n\n') + message = discord.Embed(title='Server Traffic Stats', description='Statistics on server activity\n\n',color=0x3399ff) message.set_thumbnail(url=statsThumbnailUrl) message.add_field(name='Daily Joined', value=self.dailyJoinedCount, inline='True') message.add_field(name='Daily Left', value='{0}\n'.format(self.dailyLeftCount), inline='True')