-
Notifications
You must be signed in to change notification settings - Fork 1
/
act.py
168 lines (144 loc) · 6.58 KB
/
act.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
# List specific code for IBL
#
# Replace this with code for your specific list
# Routes should be self-explanatory
import motor.motor_asyncio
import os
import secrets
import re
import datetime
import discord
import utils
import asyncio
import aiohttp
modlogs = 911907978926493716
async def integrase(app):
print("[Integrase] Start")
while True:
async with aiohttp.ClientSession() as sess:
async with sess.get("https://catnip.metrobots.xyz/bots") as resp:
if not resp.ok:
continue
resp = await resp.json()
for bot in resp:
if not bot["cross_add"]:
continue
_bot = await app.mongo.bots.find_one({"botID": bot["bot_id"]})
if not _bot:
print("[Integrase]", bot["bot_id"])
await asyncio.sleep(60*30)
async def prepare(app):
"""This sets up the mongodb database. It is a TODO"""
# TODO: ask toxic if this is correct?
app.mongo = motor.motor_asyncio.AsyncIOMotorClient(os.environ.get("MONGO_URL"))[os.environ.get("MONGO_DBNAME")]
async def claim(app, bot, _secrets):
_bot = await app.mongo.bots.find_one({"botID": bot.bot_id})
if not _bot:
# We do not want to send any thing or do anything in claim/unclaim/deny if bot does not already exist
return
if _bot.get("type") != "pending" or not _bot.get("type"):
print("Ignoring")
return
# Hopefully
await app.mongo.bots.update_one({"botID": bot.bot_id}, {"$set": {"claimed": True, "claimedBy": bot.reviewer}})
# TODO: ask toxic to make a proper claim embed
async def unclaim(app, bot, _secrets):
_bot = await app.mongo.bots.find_one({"botID": bot.bot_id})
if not _bot:
# We do not want to send any thing or do anything in claim/unclaim/deny if bot does not already exist
return
if _bot["type"] != "pending":
print("Ignoring")
return
await app.mongo.bots.update_one({"botID": bot.bot_id}, {"$set": {"claimed": False, "claimedBy": ""}})
async def approve(app, bot, _secrets):
_bot = await app.mongo.bots.find_one({"botID": bot.bot_id})
if not _bot:
if not bot.cross_add:
if bot.list_source != "3b50d5e8-d0a0-4e63-aff7-f81068e9ad36":
print("Not cross addable")
return
# We need to insert a bot here
await app.mongo.bots.insert_one({
"botID": bot.bot_id,
"botName": bot.username,
"vanity": re.sub('[^a-zA-Z0-9]', '', bot.username).lower(),
"note": "Metro-approved",
"date": datetime.datetime.now(),
"prefix": bot.prefix or "/",
"website": bot.website or "None",
"github": bot.github or "None",
"donate": bot.donate or "None",
"nsfw": bot.nsfw,
"library": bot.library,
"short": bot.description,
"long": bot.long_description,
"tags": ", ".join(bot.tags),
"invite": bot.invite or f"https://discord.com/oauth2/authorize?client_id={bot.bot_id}&permissions=0&scope=bot%20applications.commands",
"main_owner": bot.owner,
"additional_owners": bot.extra_owners,
"webAuth": "None",
"webURL": "None",
"webhook": "None",
"token": secrets.token_urlsafe(),
"type": "pending"
})
_bot = {"type": "pending"}
if _bot.get("type") != "pending" or not _bot.get("type"):
print("Ignoring")
return
await app.mongo.bots.update_one({"botID": bot.bot_id}, {"$set": {"type": "approved"}})
embed = discord.Embed(title="**__Bot Approved:__**", color=discord.Color.from_rgb(19, 76, 173))
embed.set_thumbnail(url="https://cdn.discordapp.com/attachments/815094858439065640/972734471369527356/FD34E31D-BFBC-4B96-AEDB-0ECB16F49314.png")
embed.add_field(name="Bot:", value=f"<@{bot.bot_id}>", inline=True)
embed.add_field(name="Owner:", value=f"<@{bot.owner}>", inline=True)
embed.add_field(name="Moderator:", value=f"<@{bot.reviewer}>", inline=True)
embed.add_field(name="Feedback:", value=f"{bot.reason}", inline=True)
embed.set_footer(text="© Copyright 2021 - 2022 - Metro Reviewers")
embed.timestamp = datetime.datetime.now()
asyncio.create_task(utils.msg_sender(_secrets["token"], modlogs, embed))
async def deny(app, bot, _secrets):
_bot = await app.mongo.bots.find_one({"botID": bot.bot_id})
if not _bot:
if not bot.cross_add:
print("Not cross addable")
return
# We need to insert a bot here
await app.mongo.bots.insert_one({
"botID": bot.bot_id,
"botName": bot.username,
"vanity": re.sub('[^a-zA-Z0-9]', '', bot.username).lower(),
"note": "Metro-denied",
"date": datetime.datetime.now(),
"prefix": bot.prefix or "/",
"website": bot.website or "None",
"github": bot.github or "None",
"donate": bot.donate or "None",
"nsfw": bot.nsfw,
"library": bot.library,
"short": bot.description,
"long": bot.long_description,
"tags": ", ".join(bot.tags),
"invite": bot.invite or f"https://discord.com/oauth2/authorize?client_id={bot.bot_id}&permissions=0&scope=bot%20applications.commands",
"main_owner": bot.owner,
"additional_owners": bot.extra_owners,
"webAuth": "None",
"webURL": "None",
"webhook": "None",
"token": secrets.token_urlsafe(),
"type": "pending"
})
_bot = {"type": "pending"}
if _bot.get("type") != "pending" or not _bot.get("type"):
print("Ignoring")
return
await app.mongo.bots.update_one({"botID": bot.bot_id}, {"$set": {"type": "denied"}})
embed = discord.Embed(title="**__Bot Denied :(:__**", color=discord.Color.from_rgb(19, 76, 173))
embed.set_thumbnail(url="https://cdn.discordapp.com/attachments/815094858439065640/972734471369527356/FD34E31D-BFBC-4B96-AEDB-0ECB16F49314.png")
embed.add_field(name="Bot:", value=f"<@{bot.bot_id}>", inline=True)
embed.add_field(name="Owner:", value=f"<@{bot.owner}>", inline=True)
embed.add_field(name="Moderator:", value=f"<@{bot.reviewer}>", inline=True)
embed.add_field(name="Reason:", value=f"{bot.reason}", inline=True)
embed.set_footer(text="© Copyright 2021 - 2022 - Metro Reviewers")
embed.timestamp = datetime.datetime.now()
asyncio.create_task(utils.msg_sender(_secrets["token"], modlogs, embed))