-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStats.py
More file actions
172 lines (111 loc) · 5.4 KB
/
Copy pathStats.py
File metadata and controls
172 lines (111 loc) · 5.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# imports
import discord
from discord.ext import commands
from discord.ext.commands import Bot
from discord.voice_client import VoiceClient
from discord.utils import find
from operator import itemgetter
import asyncio
import datetime
import db_commands
import utils
import os
import psutil
import time
from datetime import timedelta
db = db_commands.DB()
class Stats(commands.Cog):
def __init__(self,bot):
self.bot = bot
@commands.command(pass_context=True, aliases=['tm'])
async def total_msg(self, ctx):
totalmsgs = db.getTotalMsgs(ctx.guild.id)
embedMsg = discord.Embed(title="Total Messages", description=totalmsgs)
await ctx.send(embed=embedMsg)
@commands.command(pass_context=True, aliases=['tm-c'])
async def total_msg_channel(self, ctx):
totalmsgs = db.getTotalMsgsChannel(ctx.channel.id,ctx.guild.id)
embedMsg = discord.Embed(title="Total Messages in #{}".format(ctx.channel.name), description=totalmsgs,color=0x00ff40)
await ctx.send(embed=embedMsg)
@commands.command(pass_context=True, aliases=['mm'])
async def my_messages(self, ctx, member: discord.Member = None):
member = ctx.author if not member else member
userMsgs = db.getTotalMsgsUser(member.id,ctx.guild.id)
if not userMsgs:
await ctx.send("User Not Found")
else:
embedMsg = discord.Embed(title="{}'s Total Messages in {}".format(member.name,ctx.guild.name), description=userMsgs,color=0x00ff40)
await ctx.send(embed=embedMsg)
@commands.command(pass_context=True, aliases=['avg-msg'])
async def avg_msg(self, ctx):
totalmsgs = db.getTotalMsgs(ctx.guild.id)
time = db.getDayAdded(ctx.guild.id)
avgMsg = utils.getAvgMessage(time,totalmsgs)
embed = discord.Embed(title="Average Messages Per Day", description=str(int(avgMsg)),color=0x00ff40)
await ctx.send(embed=embed)
@commands.command(pass_context=True, name='dashboard')
async def dashboard(self, ctx):
state = db.getPublicStatus(ctx.guild.id)
vc=f"https://antonn.ml/dashboard?ID={ctx.guild.id}"
embed=discord.Embed(title="Dashboard For {}".format(ctx.guild.name), url=vc, description="", color=0x00ff40)
if not state:
embed.add_field(name="State",value="Private")
await ctx.send(embed=embed)
@commands.command(pass_context=True, aliases=['dashboard-public'])
async def dashboard_public(self, ctx):
status = db.getPublicStatus(ctx.guild.id)
await ctx.send(str(status))
@commands.command(pass_context=True, aliases=['set-dashboard-public'])
@commands.has_permissions(administrator=True)
async def set_dashboard_public(self, ctx,state):
if state == "true" or state == "True":
public = True
db.setPublicStatus(ctx.guild.id,public)
await ctx.send("Dashboard is now Public")
return
if state == "false" or state == "False":
public = False
db.setPublicStatus(ctx.guild.id,public)
await ctx.send("Dashboard is now Private")
return
else:
await ctx.send("Retry the command with either True or False")
@commands.command(pass_context=True, name="stats")
async def stat(self, ctx):
link=f"https://antonn.ml/dashboard?ID={ctx.guild.id}"
guildData = db.getAll(ctx.guild.id)
avgMsg = utils.getAvgMessage(guildData['time'],guildData['total_msg'])
activeMem = guildData['members']
SortedActiveMem = sorted(activeMem, key=itemgetter('total_msg'), reverse=True)
activeCha = guildData['channels']
SortedActiveCha = sorted(activeCha, key=itemgetter('total_msg'), reverse=True)
description_names = ""
description_msgs = ""
for i in SortedActiveMem[:10]:
member = ctx.guild.get_member(i['id'])
description_names += "{}\n".format(member.mention)
for i in SortedActiveMem[:10]:
description_msgs += "{}\n".format(i['total_msg'])
description_names2 = ""
description_msgs2 = ""
for i in SortedActiveCha[:10]:
channel = ctx.guild.get_channel(i['id'])
description_names2 += "{}\n".format(channel.mention)
for i in SortedActiveCha[:10]:
description_msgs2 += "{}\n".format(i['total_msg'])
embed = discord.Embed(title="Stats For {}".format(ctx.guild.name),url=link, color=0x00ff40)
embed.add_field(name="Messages", value=guildData['total_msg'])
embed.add_field(name="Avg Messages", value=round(avgMsg))
embed.add_field(name="Today", value=guildData['dailyCount'])
embed.add_field(name="Active Members\n\n", value=description_names)
embed.add_field(name="Messages\n\n", value=description_msgs)
embed.add_field(name="Members", value=len(guildData['members']))
embed.add_field(name="Active Channels\n\n", value=description_names2)
embed.add_field(name="Messages\n\n", value=description_msgs2)
embed.add_field(name="Channels", value=len(guildData['channels']))
embed.add_field(name="__Dashboard__",value=link)
if not guildData['public']:
embed.add_field(name="Dashboard State",value="Private")
await ctx.send(embed=embed)
def setup(bot):
bot.add_cog(Stats(bot))