-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
229 lines (168 loc) · 6.4 KB
/
bot.py
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# 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 matplotlib.pyplot as plt
from matplotlib.ticker import MaxNLocator
import numpy as np
import db_commands
import utils
import os
import psutil
import time
import datetime
from datetime import timedelta
from dotenv import load_dotenv
# Prefix
bot = commands.Bot(command_prefix="%")
bot.remove_command('help')
bot.load_extension("Stats")
db = db_commands.DB()
load_dotenv()
token = os.getenv('token')
# Events
#***************************************
@bot.event
async def on_ready():
await bot.change_presence(activity=discord.Game(name="%help"))
print("Up and Running")
@bot.event
async def on_guild_join(guild):
guildChannels = utils.getGuildChannels(guild.text_channels)
guildMembers = utils.getGuildMembers(guild.members)
password = utils.generatePass();
guildData = {"name": guild.name,
"id": guild.id,
"total_msg": 0,
"total_voice": 0,
"channels": guildChannels,
"members": guildMembers,
"time": datetime.datetime.now().timestamp(),
"dailyCount": 0,
"dailyVoice": 0,
"dailyCounts": [],
"memberCounts": [],
"voiceCounts": [],
"public":True,
"password": password}
db.addServer(guildData)
general = find(lambda x: x.name == "general", guild.text_channels)
await general.send("Hello!! Type %help")
@bot.event
async def on_member_join(member):
if member.bot:
return
newMember = {
'id': member.id,
'name': member.display_name,
'total_msg': 0,
'voice': 0,
'voiceState': {'joined': None, 'left': None}
}
db.addMember(newMember,member.guild.id)
@bot.event
async def on_guild_channel_create(channel):
if channel.type == discord.ChannelType.text:
newChannel = {
'name': channel.name,
'id': channel.id,
'total_msg': 0,
}
db.addChannel(newChannel,channel.guild.id)
print("channel added")
@bot.event
async def on_guild_remove(guild):
db.removeGuild(guild.id)
@bot.event
async def on_member_remove(member):
db.removeMember(member.id,member.guild.id)
@bot.event
async def on_guild_channel_delete(channel):
db.removeChannel(channel.id,channel.guild.id)
# Status getting Passed as Activity, Not Fixed Yet
"""
@bot.event
async def on_member_update(memBefore,memAfter):
if memAfter.bot:
return
if memAfter.activity == None:
return
validActivity = utils.checkActivitiy(memAfter.activity.type)
if validActivity:
if memBefore.activity == None:
db.updateActivity(memAfter.guild.id, memAfter.activity)
return
if memBefore.activity.name != memAfter.activity.name:
db.updateActivity(memAfter.guild.id, memAfter.activity)
"""
@bot.event
async def on_voice_state_update(member,before,after):
if before.channel == None:
if after.channel:
db.addJoinedTime(member.guild.id,member.id)
if before.channel:
if after.channel == None:
db.addLeftTime(member.guild.id,member.id)
if before.channel:
if after.channel:
if before.channel.name != after.channel.name:
db.addJoinedTime(member.guild.id,member.id)
@bot.event
async def on_message(message):
if message.author.bot:
return
db.updateCount(message.guild.id,message.author, message.channel)
await bot.process_commands(message)
@bot.command(name="help")
async def helpCommand(ctx):
helpDetails = ""
helpDetails += "**Prefix: %** \n\n"
helpDetails += "**General Stats\n\n**"
helpDetails += "`%stats` - Get Full Stats\n"
helpDetails += "`%tm` - Get Total Messages\n"
helpDetails += "`%tm-c` - Get Total Messages of the current channel\n"
helpDetails += "`%mm <ping@user>` - Get your Total Messages in the server/Get pinged user's total messages in the server\n"
helpDetails += "`%avg-msg ` - Get Daily Average Messages\n\n"
helpDetails += "**Web Dashboard**\n\n"
helpDetails += "`%dashboard` - Get Link to the Web Dashboard\n"
helpDetails += "`%dashboard-public` - See if Dashboard is Public Or Private\n"
helpDetails += "`%set-dashboard-public <true/false>` - Set Web Dashboard Public or Private\n\n"
helpDetails += "**Others**\n\n"
helpDetails += "`%about` - About Antonn\n"
helpDetails += "`%invite` - Get Bot Invite Link\n\n"
helpDetails += "invite - https://bit.ly/3md6zi0\n"
helpDetails += "Created by **sayyss#9603**"
embed = discord.Embed(title="Help",description=helpDetails, color=0x00ff40)
await ctx.send(embed=embed)
@bot.command(name="about")
async def about(ctx):
guildCount = len(bot.guilds)
userCount = len(bot.users)
process = psutil.Process()
embed = discord.Embed(title="About Antonn", description="Stat Bot",color=0x00ff40)
embed.add_field(name="**__General Info__**", inline=False, value="\u200b")
embed.add_field(name="Latency", value=f"{bot.latency*1000:.03f}ms")
embed.add_field(name="Guild Count", value=guildCount)
embed.add_field(name="User Count", value=userCount)
embed.add_field(name="**__Technical Info__**", inline=False, value="\u200b")
embed.add_field(name="System CPU Usage", value=f"{psutil.cpu_percent():.02f}%")
embed.add_field(name="System RAM Usage",
value=f"{psutil.virtual_memory().used/1048576:.02f} MB")
embed.add_field(name="System Uptime",
value=f'{timedelta(seconds=int(time.time() - psutil.boot_time()))}')
embed.add_field(name="Bot CPU Usage", value=f"{process.cpu_percent():.02f}%")
embed.add_field(name="Bot RAM Usage", value=f"{process.memory_info().rss / 1048576:.02f} MB")
embed.add_field(name="Bot Uptime",
value=f'{timedelta(seconds=int(time.time() - process.create_time()))}')
await ctx.send(embed=embed)
@bot.command(name="invite")
async def invite(ctx):
link = "https://discord.com/api/oauth2/authorize?client_id=733732900939366427&permissions=8&scope=bot"
embed = discord.Embed(title="Invite Link",url=link, color=0x00ff40)
await ctx.send(embed=embed)
bot.run(token)