-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommands.py
More file actions
57 lines (50 loc) · 2.11 KB
/
Copy pathcommands.py
File metadata and controls
57 lines (50 loc) · 2.11 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
import config
import discord
from discord.ext import commands
import sqlite3
def add_username(irl, game, username):
try:
with conn:
c.execute("""INSERT INTO users (irl, game, username)
VALUES (?, ?, ?)
""", (irl.lower(), game.lower(), username.lower()))
await ctx.send('Added {} to {} for user {}'.format(args[2], args[1], args[0]))
except:
await ctx.send('Invalid arguments! Try checking to make sure it\'s $dnsbot {user} {game} {username}')
def grab_username(irl, game):
try:
with conn:
c.execute("""SELECT username FROM users
WHERE irl=? AND game=?
""", (irl.lower(), game.lower()))
response = c.fetchone()[0]
await ctx.send('{}\'s username for {} is '.format(args[0], args[1]) + response + '.')
except:
await ctx.send('Invalid arguments!')
def start_bot(client, conn, c):
@client.event
async def on_ready():
print('Bot is ready.')
@client.event
async def on_member_join(member):
print(f'{member} has joined the server')
@client.event
async def on_member_remove(member):
print(f'{member} has left the server')
@client.command()
async def dnsbot(ctx, flag = None, *args):
if flag is None or flag[0] != '-':
await ctx.send('Type "dnsbot -h" for help')
else:
arg_num = len(args)
if flag == '-a' and arg_num == 3:
add_username(args[0], args[1], args[2])
elif flag == '-h':
await ctx.send('`Usage: $dnsbot [-ahg] [args]\n' +
'a: add username for specified user and game [-a user game username]\n' +
'h: print this help message\n' +
'g: get the username for a specified user and game`')
elif flag == '-g' and arg_num == 2:
grab_username(args[0], args[1])
else:
await ctx.send('Invalid flag or number of arguments')