-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbot.py
More file actions
192 lines (155 loc) · 6.67 KB
/
bot.py
File metadata and controls
192 lines (155 loc) · 6.67 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
import os
import discord
from discord import app_commands
from discord.ext import tasks, commands
import datetime
import asyncio
import aiohttp
from pymongo import MongoClient
from dotenv import load_dotenv
# import cogs
from cogs.bots import Bot
from cogs.misc import Misc
from cogs.mc import Minecraft
from cogs.web import Web
load_dotenv()
# database connection
cluster = MongoClient(os.environ.get("mongo"))
db = cluster["discord"]
collection = db["status"]
# enabling intents
intents = discord.Intents.all()
intents.members = True
# defining the bot, the application commands and the start time
startTime = 0
bot = commands.Bot(command_prefix="/", intents=intents)
@bot.event
async def on_ready(): # When the bot is ready
print("Ready!")
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="over your bots!"))
print(bot.user) # Prints the bot's username and identifier
try:
bot.tree.add_command(Bot())
bot.tree.add_command(Misc())
bot.tree.add_command(Minecraft())
await bot.load_extension("cogs.web")
await bot.tree.sync() # Syncs the command tree
except: return
updated = []
@bot.event
async def on_presence_update(before,after):
if not before.bot:
return
if before.status == after.status:
return
if before.id in updated:
return
updated.append(before.id)
try:
await asyncio.sleep(10)
double_check = bot.get_user(before.id)
if before.status != double_check.status:
return
except:
pass
user = bot.get_user(before.id)
try:
results = collection.find()
for result in results:
if str(result["_id"]) != str(user.id):
# pass do literally nothing
pass
else:
for query in result:
if str(query) == "_id":
pass
else:
server = result[query]
channel = bot.get_channel(server[0])
msg = await channel.fetch_message(server[1])
down_message = server[2]
auto_publish = server[3]
owner = int(server[4])
lock = server[5]
if str(after.status) == "online":
await msg.edit(content=f"<:online:949589635061915648> {user.mention} is online")
if lock == True:
perms = channel.overwrites_for(channel.guild.default_role)
perms.send_messages=True
await channel.set_permissions(channel.guild.default_role, overwrite=perms)
elif str(after.status) == "idle":
await msg.edit(content=f"<:idle:949589635087081503> {user.mention} is on idle")
if lock == True:
perms = channel.overwrites_for(channel.guild.default_role)
perms.send_messages=True
await channel.set_permissions(channel.guild.default_role, overwrite=perms)
elif str(after.status) == "dnd":
await msg.edit(content=f"<:dnd:949589635091284019> {user.mention} is on do not disturb")
if lock == True:
perms = channel.overwrites_for(channel.guild.default_role)
perms.send_messages=True
await channel.set_permissions(channel.guild.default_role, overwrite=perms)
else:
await msg.edit(content=f"<:offline:949589634898350101> {user.mention} is offline")
if lock == True:
perms = channel.overwrites_for(channel.guild.default_role)
perms.send_messages=False
await channel.set_permissions(channel.guild.default_role, overwrite=perms)
down_msg = await channel.send(down_message)
if auto_publish == True:
try:
await down_msg.publish()
except:
pass
try:
user = bot.get_user(owner)
await user.send(down_message)
except:
pass
except Exception as e:
print(e)
pass
await asyncio.sleep(10)
updated.remove(before.id)
@bot.event
async def on_guild_remove(guild):
channel = bot.get_channel(947126649378447400)
embed=discord.Embed(title="I Left a guild", description=f"{guild.name}", color=0xfa0505)
embed.timestamp = datetime.datetime.utcnow()
await channel.send(embed=embed)
collection.update_many( { }, { "$unset": { str(guild.id): "" } } )
results = collection.find()
for result in results:
counter = 0
for query in result:
if str(query) == "_id":
# this is the objects ID, all objects have this
pass
else:
counter = counter + 1
if counter == 0:
try:
collection.delete_one(result)
except:
pass
@bot.event
async def on_guild_join(guild):
channel = bot.get_channel(947126649378447400)
embed=discord.Embed(title="I joined a guild", description=f"{guild.name}", color=0x5bfa05)
embed.timestamp = datetime.datetime.utcnow()
await channel.send(embed=embed)
async with aiohttp.ClientSession() as session:
top = "https://top.gg/api/bots/845943691386290198/stats"
dsl = "https://api.discordlist.space/v2/bots/845943691386290198"
dbg = "https://discord.bots.gg/api/v1/bots/845943691386290198/stats"
async with session.post(top,headers={"Authorization": os.getenv("top")},json={"server_count": int(len(bot.guilds))}) as resp:
response = await resp.json()
pass
async with session.post(dsl,headers={"Authorization": os.getenv("dsl")},json={"serverCount": int(len(bot.guilds))}) as resp:
response = await resp.json()
pass
async with session.post(dbg,headers={"Authorization": os.getenv("dbg")},json={"guildCount": int(len(bot.guilds))}) as resp:
response = await resp.json()
pass
# runs the bot
bot.run(os.environ.get("DISCORD_TOKEN"))