-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
114 lines (94 loc) · 2.83 KB
/
bot.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
# bot.py
import os
import random
import discord
from discord.ext import tasks
from dotenv import load_dotenv
import pickle
import asyncio
from pynput.keyboard import Key, Controller
load_dotenv()
TOKEN = os.getenv("DISCORD_TOKEN")
client = discord.Client()
keyboard = Controller()
user_data = {}
game_started = False
input_time = 5
cooldown_time = 10
input_array = []
hunt = False
# Load data (deserialize)
if os.path.exists("data.pickle"):
with open("data.pickle", "rb") as handle:
user_data = pickle.load(handle)
@client.event
async def on_ready():
print(f"{client.user} has connected to Discord!")
@client.event
async def on_message(message):
if message.author == client.user:
return
content = message.content.lower()
# Start all commands with Matt or matt
if content.startswith("matt"):
content = content[4:].strip()
username = message.author.name
if content.startswith("start") or content.startswith("begin"):
await message.channel.send(
"Hey there travellers!"
)
await message.channel.send(
"A new game of Oregon Trail starts in 10 seconds. Make sure the host has the Oregon Trail window in focus."
)
await asyncio.sleep(10)
await message.channel.send(
"The game has begun. Good luck to all!"
)
if content.startswith("cooldown"):
m_array = content.split()
if isnumeric(m_array[1]):
cooldown_time = int(m_array[1])
await message.channel.send(
"Cooldown time set to " + m_array[1] + "."
)
else:
await message.channel.send(
"Woah there, I don't understand. Set cooldown time by typing 'matt cooldown 20'"
)
if content.startswith("input"):
m_array = content.split()
if isnumeric(m_array[1]):
cooldown_time = int(m_array[1])
await message.channel.send(
"Input time set to " + m_array[1] + "."
)
else:
await message.channel.send(
"Woah there, I don't understand. Set input time by typing 'matt input 20'"
)
async def process_input():
await client.wait_until_ready()
if game_started:
await message.channel.send(
"What do you want to do travellers?"
)
chosen_input = ""
await asyncio.sleep(input_time)
# DO STUFF WITH INPUTS
await message.channel.send(
"Alright, you chose **" + chosen_input + "**"
)
await asyncio.sleep(cooldown_time)
else:
await asyncio.sleep(5)
def update_user_data(user, key, value):
if user not in user_data:
user_data[user] = {}
user_data[user][key] = value
store_user_data()
def store_user_data():
# Store data (serialize)
with open("data.pickle", "wb") as handle:
pickle.dump(user_data, handle, protocol=pickle.HIGHEST_PROTOCOL)
client.loop.create_task(process_input())
client.run(TOKEN)