diff --git a/erikfunctions.py b/erikfunctions.py index 7755d7b..d3f6ade 100644 --- a/erikfunctions.py +++ b/erikfunctions.py @@ -3,62 +3,95 @@ import discord import asyncio import random from botClient import client +import aiohttp +import json +import pprint +import aiofiles + class ErikFunctions: + # Greets= ("hello", "hi", "greetings", "sup", "good evening", "good morning", "helo", "bonjour",) ##person greet + + # Respons = ["'sup bro", "hey", "good morning", "hello"] ##bot greet + + # Questions = ("how are you doing?", "how are you?") ##person asks bto how he is + + # QuestionRespond = ["I'am doing great", "I'm doing fine", "I'm alright", "I'm doing terrible", + # "I'm doing really bad", "I'm doing bad"] ##bot can choose to answer + + # Simple_asking_questions = ["And what about you?", "how bout you?", "what about you?", + # "and you?"] ##after answering bot asks the same to person + def __init__(self, client): self.client = client - @commands.command(aliases = ['deletem']) + @commands.command(aliases=['deletem']) async def clear(self, ctx, amount=100): - await ctx.message.channel.purge(limit=int(amount + 1)) + await ctx.message.channel.purge(limit=int(amount + 1)) # deletes amount of lines you want to delete @commands.command() async def ping(self, ctx): - await ctx.send('Pong!') + await ctx.send('Pong!') # when program is called bot replies with the pong @commands.command() async def echo(self, ctx, *args): # we can pass infinite amount of arguments by using *args answer = '' - for word in args: - answer += word + for word in args: # bot takes words , and ittereates when all the words from the user is done + answer += word # it adds words to the answer answer += ' ' - await ctx.send(answer) + await ctx.send(answer) # prints out the same words as the user inputed - @commands.command() - async def rockpaper(self, ctx): - await ctx.send('Choose rock, paper or scissors.') - def pred(m): - return m.author == ctx.author and m.channel == ctx.channel - try: - msg = await client.wait_for('message', check=pred, timeout=5) - except asyncio.TimeoutError: - await ctx.send('Time is up.') - return + @commands.command(aliases = ['rps']) + async def rockpaper(self, ctx, userChoice = " "): gamelist = ['rock', 'paper', 'scissors'] - gamenumber = random.randint(0, 2) - - if str(msg.content) in gamelist: - if str(msg.content) == str(gamelist[gamenumber]): - await ctx.send("Bot chose: " + str(gamelist[gamenumber])) - await ctx.send('Draw') + gamenumber = random.randint(0, 2) # generates random numbers between 0 - 2 + botChice = str(gamelist[gamenumber]) # adds numbers to the string values + if userChoice == " ": + await ctx.send('Choose rock, paper or scissors.') + def pred(m): + return m.author == ctx.author and m.channel == ctx.channel # program only works with the user who only call the program + + try: + msg = await client.wait_for('message', check=pred, timeout=5) + except asyncio.TimeoutError: + await ctx.send('Time is up.') + return + userChoice = msg.content + + if userChoice in gamelist: + if userChoice == str(gamelist[gamenumber]): # basic game explanation which one wins. + await ctx.send("Bot chose: " + str(botChice)) + await ctx.send('Its a Draw!!') else: - await ctx.send("Bot chose: " + str(gamelist[gamenumber])) - await ctx.send('Not draw') + await ctx.send("Bot chose: " + str(botChice)) + if userChoice == 'rock' and botChice == 'scissors': + await ctx.send('You win!!') + if userChoice == 'rock' and botChice == 'paper': + await ctx.send('You loose, bot wins!') + if userChoice == 'scissors' and botChice == 'rock': + await ctx.send('You loose, bot wins!') + if userChoice == 'scissors' and botChice == 'paper': + await ctx.send('You win!!') + if userChoice == 'paper' and botChice == 'rock': + await ctx.send('You win!!') + if userChoice == 'paper' and botChice == 'scissors': + await ctx.send('You loose, bot wins!') + else: await ctx.send('You cannot type that') @commands.command() async def dice(self, ctx): - if ctx.author.id == 326648914205736960: + if ctx.author.id == 326648914205736960: # only specific id which person has can use this program await ctx.send('Please choose a number between 1 - 6') def person(a): return a.author == ctx.author and a.channel == ctx.channel msg = await client.wait_for('message', check=person, timeout=5) - dicenumber = random.randint(1, 6) + dicenumber = random.randint(1, 6) # generates numbers between 1 , 6 if str(msg.content) == str(dicenumber): await ctx.send('You won') @@ -88,6 +121,134 @@ class ErikFunctions: embed.set_footer(text=f'Requested by {ctx.message.author.name}', icon_url=ctx.message.author.avatar_url) await ctx.send(embed=embed) + @commands.command() + async def gamble(self, ctx, bet = 0, cards = 0): + + """Creates the set for the complete list of cards""" + CardList = {'clubs ace', 'clubs 2', 'clubs 3', 'clubs 4', 'clubs 5', 'clubs 6', 'clubs 7', 'clubs 8', + 'clubs 9', 'clubs 10', 'clubs jack', 'clubs queen', 'clubs king', + 'diamonds ace', 'diamonds 2', 'diamonds 3', 'diamonds 4', 'diamonds 5', 'diamonds 6', 'diamonds 7', + 'diamonds 8', 'diamonds 9', 'diamonds 10', 'diamonds jack', 'diamonds queen', 'diamonds king', + 'hearts ace', 'hearts 2', 'hearts 3', 'hearts 4', 'hearts 5', 'hearts 6', 'hearts 7', 'hearts 8', + 'hearts 9', 'hearts 10', 'hearts jack', 'hearts queen', 'hearts king', + 'spades ace', 'spades 2', 'spades 3', 'spades 4', 'spades 5', 'spades 6', 'spades 7', 'spades 8', + 'spades 9', 'spades 10', 'spades jack', 'spades queen', 'spades king'} + + """The function which checks the user""" + def user(UI): + return UI.author == ctx.author and UI.channel == ctx.channel + + """If user didn't input a bet in the original command, ask him for desired bet amount. Also checks + whether the bet amount is valid (a number and max 10k). Haven't added max attempts though""" + if bet == 0: + await ctx.send('Please enter bet amount.') + try: + bet = int(await client.wait_for('message', check=user, timeout=20)) + while not bet.content.isdigit() or bet.content > 10000: + await ctx.send('You must input a number, max 10000.') + try: + bet = await client.wait_for('message', check=user, timeout=20) + except asyncio.TimeoutError: + await ctx.send('Time is up') + return + except asyncio.TimeoutError: + await ctx.send('Time is up') + return + + """Same thing with bets, but with cards this time. Must be an integer and maximum is 4""" + if cards == 0: + await ctx.send('How many cards?') + try: + cards = await client.wait_for('message', check=user, timeout=20) + while not cards.isdigit() or bet > 4: + await ctx.send('You must input a number, max 4.') + try: + bet = await client.wait_for('message', check=user, timeout=20) + except asyncio.TimeoutError: + await ctx.send('Time is up') + return + except asyncio.TimeoutError: + await ctx.send('Time is up') + return + + """Generated the random bot cards, and makes them a set""" + botCards = random.sample(CardList, cards) # generates specific amount of strings in this case is 4 + botCards = set(botCards) + """Creates an empty set in which we will add the user cards""" + userCards = set() + """User inputs a card, we add it into the userCards set. Repeat this as many times as range(cards) chosen.""" + for cardNo in range(cards): + try: + userInput = await client.wait_for('message', check=user, timeout=20) + if userInput not in CardList: + await ctx.send('Selected card does not exist. Try again') + for attempt in range(3): + try: + userInput = await client.wait_for('message', check=user, timeout=20) + + except asyncio.TimeoutError: + await ctx.send('Time is up. Game reset.') + return + userCards.add(userInput) + except asyncio.TimeoutError: + await ctx.send('Time is up') + return + + """If, when comparing user cards and bot cards, we find at least one similarity, the user wins. Otherwise, + the user loses. I HAVEN'T ADDED ANY BETS FUNCTION, JUST THE BAREBONE GAME. this function may not even work yet + so test it and see what's wrong, but the mindset is correct I believe""" + if userCards.intersection(botCards): + await ctx.send('You win') + else: + await ctx.send('You lose') + + + +""" + try: + msg1 = await client.wait_for('message', check=user, timeout=20) + await ctx.send('How many cards you want to guess, maximum limit is 4: ') + await client.wait_for('message', check=user, timeout=200) + + except asyncio.TimeoutError: + await ctx.send('Time is up.') + return + + n = 1 + a = [] + playerGuesses = [] + playerGuesses.append((arg2)) + print(playerGuesses) + + for i in range(format(arg)): + await ctx.send('kortos rusis: ') + await client.wait_for('message', check=user, timeout=200) + a.append(format(arg)) + n = n + 1 + +""" + + + + + # @client.event() + #async def greetings(self, ctx, message): + + #def pred(m): + # return m.author == ctx.author and m.channel == ctx.chnnel + + # try: + # msg = await client.wait_for('message', check=pred, timeout=30) + # except asyncio.TimeoutError: + # await ctx.send('You cant wait that long..') + # return + # message = msg.content + + #if message.lower() in Greets: + # return random.choice(Respons) + #if message.lower() in Questions: + # return random.choice(QuestionRespond) + ", " + random.choice(Simple_asking_question) + def setup(client): - client.add_cog(ErikFunctions(client)) \ No newline at end of file + client.add_cog(ErikFunctions(client))