-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
156 lines (113 loc) · 4.38 KB
/
main.py
File metadata and controls
156 lines (113 loc) · 4.38 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
from discord.ext import commands
from os import path
import sqlite3
import asyncio
bot = commands.Bot(command_prefix='!!', self_bot=True)
with open('token.txt', 'r') as f:
token = f.read()
@bot.event
async def on_ready():
print('------')
print('Logged in as ' + str(bot.user.name) + " (" + str(bot.user.id) + ")")
print('------')
conn = sqlite3.connect('db.sqlite')
c = conn.cursor()
if not path.exists('db.sqlite'):
c.execute('''CREATE TABLE members (id text, display_name text, username text, badges text, created_at text, source text)''')
conn.commit()
print("[+] Database created successfully!")
print("[+] Cleaning database...")
c.execute(f"DELETE FROM members WHERE id = ?", (str(bot.user.id),))
conn.commit()
conn.close()
print("[+] Scanning messages...")
async def writter(member, server: str):
member_id = f"{member.id}"
if member_id == str(bot.user.id):
return False
username_bytes = member.name + "#" + member.discriminator
badges = []
if member.bot:
badges.append("Bot")
elif member.premium_since is not None:
badges.append("Nitro")
badges += member.public_flags.all()
badges = str(badges)
created_at = f"{member.created_at.strftime('%d/%m/%Y %H:%M:%S')}"
conn = sqlite3.connect('db.sqlite')
c = conn.cursor()
c.execute(f"SELECT * FROM members WHERE id = '{member_id}'")
member_info = c.fetchone()
good = False
if member_info is None:
c.execute(f"INSERT INTO members VALUES (?, ?, ?, ?, ?, ?)", (member_id, member.display_name, username_bytes, badges, created_at, str(server)))
good = True
else:
if member.display_name not in str(member_info[1]):
c.execute(f"UPDATE members SET display_name = ? WHERE id = ?", (f'{str(member_info[1])} ;;; {str(member.display_name)}', member_id))
good = True
if username_bytes not in str(member_info[2]):
c.execute(f"UPDATE members SET username = ? WHERE id = ?", (f'{str(member_info[2])} ;;; {str(username_bytes)}', member_id))
good = True
if badges not in str(member_info[3]):
c.execute(f"UPDATE members SET badges = ? WHERE id = ?", (f'{str(member_info[3])} ;;; {badges}', member_id))
good = True
if created_at not in str(member_info[4]):
c.execute(f"UPDATE members SET created_at = ? WHERE id = ?", (f'{str(member_info[4])} ;;; {str(created_at)}', member_id))
good = True
if server not in str(member_info[5]):
c.execute(f"UPDATE members SET source = ? WHERE id = ?", (f'{str(member_info[5])} ;;; {str(server)}', member_id))
good = True
conn.commit()
conn.close()
return good
threads = []
@bot.command(pass_context=True)
async def ga(ctx, time_min, first=True):
global threads
if(first):
await ctx.message.delete()
threads += [f"{ctx.guild.id}{ctx.channel.id}"]
if f"{ctx.guild.id}{ctx.channel.id}" not in threads:
return
if(time_min is None):
print("[-] !!ga <time> - Please specify a time in minutes!")
print(" example: !!ga 2")
time_min = int(time_min)
server = str(ctx.guild)
total = 0
for member in ctx.guild.members:
if(await writter(member, server)):
total += 1
print(f"+ {total} from {server.encode('utf-8')}")
await asyncio.sleep(time_min*60)
await ga(ctx, time_min, False)
@bot.command(pass_context=True)
async def kill(ctx):
global threads
await ctx.message.delete()
if f"{ctx.guild.id}{ctx.channel.id}" in threads:
threads.remove(f"{ctx.guild.id}{ctx.channel.id}")
print(f"[-] Stopped scanning {ctx.guild.name.encode('utf-8')}")
@bot.command(pass_context=True)
async def uga(ctx):
await ctx.message.delete()
server = str(ctx.guild)
total = 0
for member in ctx.guild.members:
if(await writter(member, server)):
total += 1
print(f"+ {total} from {server.encode('utf-8')}")
@bot.event
async def on_message(message):
if message.author.id == bot.user.id:
await bot.process_commands(message)
return
server = str(message.guild)
if message.guild is None:
return
member = message.guild.get_member(message.author.id)
if member is None:
return
await writter(member, server)
bot.run(token)