forked from EugeneArtes23/DeerhacksRepo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainpy.py
114 lines (97 loc) · 3.56 KB
/
mainpy.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
from email import message
from pydoc import doc
from tabnanny import check
from urllib import response
import discord
import asyncio
import random
import os
import os.path
from os import path
from discord.ext import commands
import csv
import RockPaperScissorsDeerHacks
#Creates database if non exists
def CreateCSVDB():
with open('db.csv','w+') as csvfile:
header = ['user','amount']
writer = csv.DictWriter(csvfile,fieldnames=header)
writer.writeheader()
return
def IsUserInDataBase(username):
with open('db.csv', 'r',newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
if username in row['user']:
return True
return False
def CreateUserInDB(user):
with open('db.csv','a',newline='') as csvfile:
header = ['user','amount']
writer = csv.DictWriter(csvfile, fieldnames=header)
row = {'user':user,'amount':500}
writer.writerow(row)
return
def CheckBalance(username):
with open('db.csv', 'r',newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
if username in row['user']:
print(row['amount'])
return row['amount']
def PlayRPS(playerAction=str):
RPSGame = RockPaperScissorsDeerHacks.RPS()
RPSGame.Play(playerAction)
print(f'{RPSGame.outcome}')
return RPSGame.compChoice,RPSGame.outcome
bot = commands.Bot(command_prefix="!")
@bot.event
async def on_ready():
print('we have logged in as {0.user}'.format(bot))
if (path.exists('db.csv') == False):
CreateCSVDB()
print("Created new csv file")
@bot.command()
async def create(ctx):
user = str(ctx.author).split('#')[0]
userIn = IsUserInDataBase(user)
if(userIn == False):
CreateUserInDB(user)
await ctx.channel.send("Successful made an account!")
return
elif(userIn == True):
await ctx.channel.send("You already made an account.")
return
@bot.command()
async def checkbalance(ctx):
user = str(ctx.author).split('#')[0]
await ctx.channel.send(f'Your balance is: {CheckBalance(user)}')
@bot.command()
async def hello(ctx):
user = str(ctx.author).split('#')[0]
await ctx.channel.send(f'Hello {user}!')
@bot.command()
async def goodbye(ctx):
user = str(ctx.author).split('#')[0]
await ctx.channel.send(f'See you later {user}!')
@bot.command()
async def randomnum(ctx):
response = f"This is your random number: {random.randrange(1000)}"
await ctx.channel.send(response)
@bot.command()
async def rps(ctx):
user = str(ctx.author).split('#')[0]
userIn = IsUserInDataBase(user)
if(userIn==True):
await ctx.channel.send('Please choose between "Rock","Paper","Scissors"')
try:
userAction = await bot.wait_for('message',check=lambda m: m.author == ctx.author and m.channel == ctx.channel, timeout=30.0)
except asyncio.TimeoutError:
await ctx.channel.send("Ouch you ignored me :(")
else:
if (userAction.content.lower() == "rock") or (userAction.content.lower() == "paper") or (userAction.content.lower() == "scissors"):
compChoice,outcome = PlayRPS(userAction)
await ctx.channel.send(f'You chose: {userAction.content.lower()}\nComputer picked: {compChoice.lower()}\nYou {outcome}!')
else:
await ctx.channel.send("Invaild choice try again")
bot.run(os.getenv('TOKEN'))