This repository has been archived by the owner on Sep 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
256 lines (219 loc) · 8.27 KB
/
main.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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
import nest_asyncio
from AntiSpam import AntiSpamHandler
import re
import vt
import discord
from discord.ext import commands
import random
from bs4 import BeautifulSoup
import requests
import os
from dotenv import load_dotenv
load_dotenv()
nest_asyncio.apply()
client = discord.Client()
vtclient = vt.Client(str(os.getenv('vt_TOKEN')))
images = [
'https://i.imgur.com/JQGhevZ.jpg',
'https://i.imgur.com/yl4U0ZY.jpg',
'https://i.imgur.com/NuDbYN6.jpg',
'https://i.imgur.com/OGwJeAX.jpg',
'https://i.imgur.com/IFcT93v.jpg',
'https://i.imgur.com/WAjMADM.jpg',
'https://i.imgur.com/6AiIwzp.jpg',
'https://i.imgur.com/SZWbVzh.jpg',
'https://i.imgur.com/LWMk1N3.jpg',
'https://i.imgur.com/VCmy1lp.jpg',
'https://i.imgur.com/UIHtWjS.jpg',
'https://i.imgur.com/9iUeAKt.jpg',
'https://i.imgur.com/42IdSrp.jpg',
'https://i.imgur.com/YYHB9Vm.jpg']
warn_embed_dict = {
"title": "**Dear $USERNAME**",
"description": "You are being warned for spam, please stop!",
"timestamp": True,
"color": 0xFF0000,
"footer": {"text": "$BOTNAME", "icon_url": "$BOTAVATAR"},
"author": {"name": "$GUILDNAME", "icon_url": "$GUILDICON"},
"fields": [
{"name": "Current warns:", "value": "$WARNCOUNT", "inline": False},
{"name": "Current kicks:", "value": "$KICKCOUNT", "inline": False},
],
}
client = commands.Bot(command_prefix="-", help_command=None)
url = "https://top.gg"
def getEmbed(searchQuery):
resultsPage = BeautifulSoup(requests.get(
url + searchQuery).text, 'html.parser')
results = resultsPage.find(
"div", {"id": "bot-list"}).find_all("li", {"class": "column bot-card is-3"})
embeds = []
for result in results:
embed = discord.Embed()
try:
tags = result.find("p", {"class": "card-tags"}).text
except:
tags = result.find("span", {"class": "card-tags"}).text
resultUrl = ""
try:
embed.title = result.find(
"div", {"class": "bot-name"}).text.strip()
resultUrl = resultUrl + url + \
result.find("a", {"class": "info"}).get("href")
except AttributeError:
embed.title = result.find("a", {"class": "bot-name"}).text.strip()
resultUrl = resultUrl + url + \
result.find("a", {"class": "bot-name"}).get("href")
except:
continue
embed.description = result.find("p", {"class": "bot-description"}).text
embed.set_image(url=result.find("img").get("src"))
embed.url = resultUrl
embed.add_field(name="More Info", value=resultUrl, inline=False)
embed.add_field(name="Invite", value=resultUrl +
"/invite/", inline=False)
embed.add_field(name="Tags", value=tags, inline=False)
if("Promoted" in tags):
embed.colour = 0xa39324
embeds.append(embed)
return embeds
@client.event
async def on_ready():
print(f'{client.user} has connected to Discord!')
@client.command()
async def hello(ctx):
if ctx.author == client.user:
return
await ctx.send("Hi")
@client.command(aliases=['user', 'info'])
@commands.has_permissions(kick_members=True)
async def whois(ctx, member: discord.Member):
embed = discord.Embed(
title=member.name, description=member.mention, color=discord.Colour.red())
embed.add_field(name="ID", value=member.id, inline=True)
embed.set_thumbnail(url=member.avatar_url)
await ctx.send(embed=embed)
@client.command()
async def meme(ctx):
if ctx.author == client.user:
return
embed = discord.Embed(color = discord.Colour.green())
random_link = random.choice(images)
embed.set_image(url=random_link)
await ctx.send(embed=embed)
@client.command()
async def search(ctx, *, msg):
if ctx.author == client.user:
return
searchQuery = "/search?q=" + msg
if "bot" not in searchQuery:
searchQuery = searchQuery + " bots"
embeds = getEmbed(searchQuery)
for embed in embeds:
await ctx.channel.send(embed=embed)
embed2 = discord.Embed()
embed2.title = "**End of Results**"
embed2.add_field(name="More Results: ", value=url + searchQuery)
await ctx.channel.send(embed=embed2)
@client.command()
async def top(ctx):
if ctx.author == client.user:
return
searchQuery = "/list/top"
embeds = getEmbed(searchQuery)
for embed in embeds:
await ctx.channel.send(embed=embed)
embed2 = discord.Embed()
embed2.title = "**End of Results**"
embed2.add_field(name="More Results: ", value=url + searchQuery)
await ctx.channel.send(embed=embed2)
client.handler = AntiSpamHandler(client, guild_warn_message=warn_embed_dict)
@client.command(pass_context=True)
async def mute(ctx, member: discord.Member):
if ctx.message.author.server_permissions.administrator or ctx.message.author.id == '194151340090327041':
role = discord.utils.get(member.server.roles, name='Muted')
await client.add_roles(member, role)
embed = discord.Embed(title="User Muted!", description="**{0}** was muted by **{1}**!".format(
member, ctx.message.author), color=0xff00f6)
await client.say(embed=embed)
else:
embed = discord.Embed(title="Permission Denied.",
description="You don't have permission to use this command.", color=0xff00f6)
await client.say(embed=embed)
@client.event
async def on_message(message):
await client.handler.propagate(message)
await client.process_commands(message)
if message.author == client.user:
return
msg = message.content
links_array = re.findall(r'(https?://\S+)', msg)
if (len(links_array) == 0):
return
for link in links_array:
url_id = vt.url_id(str(link))
url = vtclient.get_object("/urls/{}".format(url_id))
array = url.last_analysis_stats
# report="Url test complete!\nThe Stats are:\n"
# for key in array.keys():
# report=report+str(key)+':'+str(array[key])+'\n'
# await message.channel.send(report)
# need a dm system here
if (array["malicious"] >= 2 or array["suspicious"] >= 4):
await message.channel.send("One or more Malicious URLs detected!!")
else:
await message.channel.send("Fine!")
@client.command()
async def help(ctx):
if ctx.author == client.user:
return
helps = [
{
"command": "-help",
"description": "Shows help on how to use the bot."
},
{
"command": "-search [Search Query (Mandatory)]",
"description": "Searches [Search Query] for matching bots on https://top.gg/"
},
{
"command": "-top",
"description": "Shows top trending bots on https://top.gg/"
},
{
"command": "-tags",
"description": "Shows all available tags(categories) of bots"
},
{
"command": "-meme",
"description": "Shows a random meme."
}
]
embed = discord.Embed()
embed.title = "Bot Commands Help"
for help in helps:
embed.add_field(name="Command", value=help["command"], inline=True)
embed.add_field(name="Description",
value=help["description"], inline=True)
embed.add_field(name="-----------------------------------------",
value="----------------------------------------\n", inline=False)
await ctx.send(embed=embed)
@client.command()
async def tags(ctx):
if ctx.author == client.user:
return
searchQuery = "/tags"
resultsPage = BeautifulSoup(requests.get(url + searchQuery).text, 'html.parser')
resultWrapper = resultsPage.find_all("div",{"class":"maincon"})
results = resultWrapper[1].find_all("a")
name = ""
embed = discord.Embed()
embed.title = "All Currently Available Tags"
for result in results:
tagName = result.text.strip()
tagLink = url + result.get("href")
name = name + " [{}]({})\n ".format(tagName,tagLink)
embed.description = name
embed.set_footer(text="Click any tag to go to its page for all results. You can also search here using the search command!")
await ctx.channel.send(embed=embed)
client.run(os.getenv('TOKEN'))