-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsockbot.py
133 lines (106 loc) · 3.94 KB
/
sockbot.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
import discord
from discord.ext import commands,tasks
from discord.utils import get
import random
import sqlite3
import json
from datetime import datetime as dt
import threading as tr
import os
import asyncio
import requests
import psycopg2
mlist=[]
#const
DATABASE_URL = os.environ['DATABASE_URL']
cn = psycopg2.connect(DATABASE_URL, sslmode='require')
cur = cn.cursor()
#y = tr.Thread(target=get_members,daemon=True)
#l = tr.Thread(target=run, daemon=True)
cur.execute("SELECT token, default_cfg FROM \"bot data\";")
token = cur.fetchone()[0]
intents = discord.Intents().all()
bot = commands.Bot(command_prefix="-",intents=intents)
bot.remove_command("help")
def get_members():
mlistx=[]
global mlist
for member in bot.get_guild(824959091532890133).members:
cur.execute(f"SELECT score FROM lb WHERE id={member.id}")
if cur.fetchone() == None:
cur.execute(f"INSERT INTO lb VALUES ({member.id}, 0)")
cur.execute(f"SELECT score FROM lb WHERE id={member.id}")
score=cur.fetchone()[0]
else:
cur.execute(f"SELECT score FROM lb WHERE id={member.id}")
score=cur.fetchone()[0]
mname=f"{member.name}#{member.discriminator}"
aurl=(str(member.avatar_url))
rls=[]
for role in member.roles:
rname=str(role.name)
rcol=str(role.color)
rls.append({'name':rname,'color':rcol})
x={'name':mname,'a_urls':aurl,'score':score,'roles':rls}
mlistx.append(x)
mlist=json.dumps(mlistx)
cn.commit()
#print(mlist)
@bot.event
async def on_ready():
print(f"{bot.user.name} {bot.user.id}")
#y.start()
data_send.start()
@tasks.loop(seconds=10)
async def data_send():
get_members()
r=requests.post("http://chaircord-rl.herokuapp.com:80/webhook/leaderboardoikjrngWPOIURGBLREGOVCQNHREWQLIGFPWQOHRUCGTEQR", headers={'Content-Type':'application/json'}, data=mlist)
#print(r)
@commands.cooldown(rate=1, per=3600, type=commands.BucketType.user)
@bot.command()
async def vote(ctx,user: discord.Member,x: str):
try:
if user == ctx.author:
ctx.command.reset_cooldown(ctx)
await ctx.send("this is you, you cant")
elif user.bot:
ctx.command.reset_cooldown(ctx)
await ctx.send("this is bot...")
else:
cur.execute(f"SELECT score FROM lb WHERE id={user.id}")
d=cur.fetchone()[0]
if x == "+":
f=d+1
elif x == "-":
f=d-1
else:
ctx.command.reset_cooldown(ctx)
await ctx.send("Wrong arguments.\nUsage: `-vote @member +/-`\nFor example:`-vote <@784785353533554688> -`")
cur.execute(f"UPDATE lb SET score={f} WHERE id={user.id}")
print('pass')
await ctx.send("voted")
cn.commit()
except(discord.ext.commands.ArgumentParsingError,discord.ext.commands.MissingRequiredArgument) as e:
ctx.command.reset_cooldown(ctx)
await ctx.send(e)
@vote.error
async def v_error(ctx, error):
if isinstance(error, discord.ext.commands.CommandOnCooldown):
msg = 'This command is ratelimited, please try again in {:.0f}m'.format((error.retry_after/60))
await ctx.send(f"`{msg}`")
elif isinstance(error, discord.ext.commands.MissingRequiredArgument):
ctx.command.reset_cooldown(ctx)
await ctx.send(f"Not enough arguments.\nUsage: `-vote @member +/-`\nFor example:`-vote <@784785353533554688> -`")
elif isinstance(error, discord.ext.commands.ArgumentParsingError):
ctx.command.reset_cooldown(ctx)
await ctx.send(error)
else:
ctx.command.reset_cooldown(ctx)
raise error
@bot.command()
async def test(ctx):
await ctx.send(bot.guilds)
bot.run(token)
d=input()
if d == "":
os.kill(0)