Merge pull request #15 from Kanium/feature/trafficTracking
Traffic Tracking
This commit is contained in:
commit
79824663df
@ -3,3 +3,4 @@
|
|||||||
|
|
||||||
## Our Cogs:
|
## Our Cogs:
|
||||||
- [WelcomeCog](./welcomeCog)
|
- [WelcomeCog](./welcomeCog)
|
||||||
|
- [TrafficCog](./trafficCog)
|
||||||
28
trafficCog/README.md
Normal file
28
trafficCog/README.md
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
# 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:
|
||||||
|
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] trafficCog`
|
||||||
|
3. `[PREFIX]load trafficCog`
|
||||||
|
|
||||||
|
### To update the Cog:
|
||||||
|
- `[PREFIX]cog uninstall trafficCog`
|
||||||
|
- `[PREFIX]repo update [RepoName]`
|
||||||
|
- `[PREFIX]cog install [RepoName] trafficCog`
|
||||||
|
- `[PREFIX]load trafficCog`
|
||||||
|
|
||||||
|
### Commands
|
||||||
|
- `[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
|
||||||
5
trafficCog/__init__.py
Normal file
5
trafficCog/__init__.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
from .trafficCog import TrafficCog
|
||||||
|
from redbot.core.bot import Red
|
||||||
|
|
||||||
|
def setup(bot: Red):
|
||||||
|
bot.add_cog(TrafficCog(bot))
|
||||||
13
trafficCog/info.json
Normal file
13
trafficCog/info.json
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"author": [
|
||||||
|
"Deathblade"
|
||||||
|
],
|
||||||
|
"install_msg": "May Kanium broaden your horizons",
|
||||||
|
"name": "TrafficCog",
|
||||||
|
"short": "Tracks daily activity on the server",
|
||||||
|
"description": "Tracks incoming and outgoing member activity on the server with daily resets",
|
||||||
|
"requirements": ["datetime"],
|
||||||
|
"tags": [
|
||||||
|
"Traffic"
|
||||||
|
]
|
||||||
|
}
|
||||||
130
trafficCog/trafficCog.py
Normal file
130
trafficCog/trafficCog.py
Normal file
@ -0,0 +1,130 @@
|
|||||||
|
import discord
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
from redbot.core import Config, commands
|
||||||
|
|
||||||
|
allowed_guilds = {274657393936302080, 693796372092289024, 508781789737648138}
|
||||||
|
admin_roles = {'Developer', 'admin', 'Council'}
|
||||||
|
statsThumbnailUrl = 'https://www.kanium.org/machineroom/logomachine-small.png'
|
||||||
|
|
||||||
|
class TrafficCog(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='settrafficchannel', description='Sets the channel to sends log to')
|
||||||
|
@commands.has_any_role(*admin_roles)
|
||||||
|
async def setTrafficChannel(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',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')
|
||||||
|
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')
|
||||||
|
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.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 unbanned from the server'.format(member.mention))
|
||||||
|
self.totalLogs += 1
|
||||||
|
except (discord.NotFound, discord.Forbidden):
|
||||||
|
print(
|
||||||
|
f'Error Occured!')
|
||||||
@ -1,28 +1,32 @@
|
|||||||
# WelcomeCog
|
# 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.
|
||||||
|
|
||||||
# How to use:
|
# 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).
|
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:
|
## Requirments:
|
||||||
|
|
||||||
- Instance of [RedBot](https://github.com/Cog-Creators/Red-DiscordBot)
|
- Instance of [RedBot](https://github.com/Cog-Creators/Red-DiscordBot)
|
||||||
- Downloader cog has to be loaded. to load:
|
- Downloader cog has to be loaded. to load:
|
||||||
```[Prefix]load downloader```
|
`[Prefix]load downloader`
|
||||||
|
|
||||||
## How to install & load:
|
## How to install & load:
|
||||||
|
1. `[PREFIX]repo add [RepoName] https://github.com/Kanium/KaniumCogs [ActiveBranch (EX: Master)] `
|
||||||
1. ```[PREFIX]repo add [RepoName] https://github.com/Kanium/KaniumCogs [ActiveBranch (EX: Master)] ```
|
2. `[PREFIX]cog install [RepoName] welcomeCog`
|
||||||
2. ```[PREFIX]cog install [RepoName] welcomeCog```
|
3. `[PREFIX]load welcomeCog`
|
||||||
3. ```[PREFIX]load welcomeCog```
|
|
||||||
|
|
||||||
### To update the Cog:
|
### To update the Cog:
|
||||||
- ```[PREFIX]repo update [RepoName]```
|
- `[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
|
||||||
|
|
||||||
### To modify the sent message:
|
### To modify the sent message:
|
||||||
|
|
||||||
If you would like to modify the message to your liking, you can either :
|
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. 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.
|
- 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.
|
||||||
|
|||||||
@ -2,4 +2,4 @@ from .welcome import WelcomeCog
|
|||||||
from redbot.core.bot import Red
|
from redbot.core.bot import Red
|
||||||
|
|
||||||
def setup(bot: Red):
|
def setup(bot: Red):
|
||||||
bot.add_cog(WelcomeCog())
|
bot.add_cog(WelcomeCog(bot))
|
||||||
@ -11,7 +11,7 @@
|
|||||||
"show earnestness in the submitted application as well as in becoming part of the community."
|
"show earnestness in the submitted application as well as in becoming part of the community."
|
||||||
],
|
],
|
||||||
"color":"0x3399ff",
|
"color":"0x3399ff",
|
||||||
"thumbnail": "https://i.imgur.com/4TLdfDA.png",
|
"thumbnail": "https://www.kanium.org/machineroom/logomodern.png",
|
||||||
"fields":[
|
"fields":[
|
||||||
{"id":"text", "name":"Apply for membership", "value":"!apply <applicationText>", "inline":"True"},
|
{"id":"text", "name":"Apply for membership", "value":"!apply <applicationText>", "inline":"True"},
|
||||||
{"id":"text", "name":"Description", "value":"If you are certain about joining, use this command to do so", "inline":"True"},
|
{"id":"text", "name":"Description", "value":"If you are certain about joining, use this command to do so", "inline":"True"},
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
"author": [
|
"author": [
|
||||||
"Deathblade"
|
"Deathblade"
|
||||||
],
|
],
|
||||||
"install_msg": "May Kanuim show you the way",
|
"install_msg": "May Kanium show you the way",
|
||||||
"name": "Welcome",
|
"name": "Welcome",
|
||||||
"short": "Sends a welcome dm thats written in a specific format to the users",
|
"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",
|
"description": "Sends a welcome dm thats written in a specific format to the users",
|
||||||
|
|||||||
@ -1,16 +1,22 @@
|
|||||||
import asyncio
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import discord
|
import discord
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from redbot.core import Config, checks, commands
|
from redbot.core import Config, commands
|
||||||
from redbot.core.utils.chat_formatting import box, humanize_list, pagify
|
|
||||||
|
|
||||||
url = 'https://raw.githubusercontent.com/Kanium/KaniumCogs/master/welcomeCog/data/embedded_message.json'
|
url = 'https://raw.githubusercontent.com/Kanium/KaniumCogs/master/welcomeCog/data/embedded_message.json'
|
||||||
|
|
||||||
allowed_guilds = {274657393936302080, 693796372092289024, 508781789737648138}
|
allowed_guilds = {274657393936302080, 693796372092289024, 508781789737648138}
|
||||||
|
admin_roles = {'Developer', 'admin', 'Council'}
|
||||||
|
|
||||||
|
|
||||||
|
class WelcomeCog(commands.Cog):
|
||||||
|
|
||||||
|
def __init__(self, bot):
|
||||||
|
self.bot = bot
|
||||||
|
self.message: str = ''
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
async def fetchMessage():
|
async def fetchMessage():
|
||||||
async def fetch():
|
async def fetch():
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
@ -20,8 +26,8 @@ async def fetchMessage():
|
|||||||
return x
|
return x
|
||||||
return await fetch()
|
return await fetch()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
def formatMessage(jsonFormat):
|
def formatMessage(jsonFormat: str):
|
||||||
try:
|
try:
|
||||||
message = discord.Embed(title=str(jsonFormat['title']), description=''.join(
|
message = discord.Embed(title=str(jsonFormat['title']), description=''.join(
|
||||||
map(str, jsonFormat['description'])), color=int(jsonFormat['color'], 16))
|
map(str, jsonFormat['description'])), color=int(jsonFormat['color'], 16))
|
||||||
@ -39,37 +45,44 @@ def formatMessage(jsonFormat):
|
|||||||
return message
|
return message
|
||||||
|
|
||||||
except:
|
except:
|
||||||
message = discord.Embed(title="Kanium", description='', color=0x3399ff)
|
message = discord.Embed(
|
||||||
|
title='Kanium', description='', color=0x3399ff)
|
||||||
message.add_field(
|
message.add_field(
|
||||||
name="Welcome", value='Welcome To Kanium !', inline=True)
|
name='Welcome', value='Welcome To Kanium !', inline=True)
|
||||||
return message
|
return message
|
||||||
|
|
||||||
|
@commands.command(name='pullmessage', description='pulls the message from github again')
|
||||||
class WelcomeCog(commands.Cog):
|
@commands.has_any_role(*admin_roles)
|
||||||
def __init__(self, *args, **kwargs):
|
async def pullMessage(self, ctx: commands.Context) -> None:
|
||||||
super().__init__(*args, **kwargs)
|
try:
|
||||||
self.message = ''
|
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')
|
@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:
|
try:
|
||||||
|
await ctx.trigger_typing()
|
||||||
if ctx.guild.id not in allowed_guilds:
|
if ctx.guild.id not in allowed_guilds:
|
||||||
return
|
return
|
||||||
if self.message == '':
|
if self.message == '':
|
||||||
self.message = await fetchMessage()
|
self.message = await WelcomeCog.fetchMessage()
|
||||||
message = formatMessage(self.message)
|
message = WelcomeCog.formatMessage(self.message)
|
||||||
await ctx.send(content=None, embed=message)
|
await ctx.send(content=None, embed=message)
|
||||||
except():
|
except():
|
||||||
print(f'Error Occured!')
|
print(f'Error Occured!')
|
||||||
|
|
||||||
@commands.Cog.listener()
|
@commands.Cog.listener()
|
||||||
async def on_member_join(self, member: discord.Member):
|
async def on_member_join(self, member: discord.Member) -> None:
|
||||||
try:
|
try:
|
||||||
if member.guild.id not in allowed_guilds:
|
if member.guild.id not in allowed_guilds:
|
||||||
return
|
return
|
||||||
if self.message == '':
|
if self.message == '':
|
||||||
self.message = await fetchMessage()
|
self.message = await WelcomeCog.fetchMessage()
|
||||||
message = formatMessage(self.message)
|
message = WelcomeCog.formatMessage(self.message)
|
||||||
await member.send(content=None, embed=message)
|
await member.send(content=None, embed=message)
|
||||||
except (discord.NotFound, discord.Forbidden):
|
except (discord.NotFound, discord.Forbidden):
|
||||||
print(
|
print(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user