-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCheebs.py
182 lines (153 loc) · 5.68 KB
/
Cheebs.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# bot.py
import os
import discord
import praw
import TTTAI
import PlayTTT
import copy
import random
from dotenv import load_dotenv
load_dotenv()
client = discord.Client()
TOKEN = os.environ.get("bot-token")
reddit = praw.Reddit(
client_id=os.environ.get("client-id"),
client_secret=os.environ.get("client-secret"),
user_agent=os.environ.get("user-agent"),
)
@client.event
async def on_message(message):
if message.author == client.user:
return
print(message.author.display_name + " : " + message.content)
if message.content.startswith("$help"):
await message.channel.send(
"Cheebs here, I'm kinda new and don't know nobody, for now I just fetch reddit posts and play TicTacToe, use $reddithelp to learn more and $tictactoe to play"
)
elif message.content.startswith("$reddithelp"):
helperText = (
"So,%s you need help, and where do you come? Crawling back to me. \n Here's the lowdown - \n $reddit {subredditname} {top/hot/new/rising/controversial/gilded} {number of posts} \n $reddit {subredditname} {topnth/hotnth/newnth/risingnth/controversialnth/gildednth} {post at nth position}"
% (message.author.mention)
)
await message.channel.send(helperText)
# reddit stuff
elif message.content.startswith("$reddit"):
reddit = praw.Reddit(
client_id=os.environ.get("client-id"),
client_secret=os.environ.get("client-secret"),
user_agent=os.environ.get("user-agent"),
)
sub = "cats"
type = "top"
lim = 1
li = message.content.split()
print(li[0])
if len(li) > 1:
print(li[1])
sub = li[1]
if len(li) > 2:
print(li[2])
type = li[2]
if len(li) > 3:
print(li[3])
lim = int(li[3])
submission_list = (
reddit.subreddit(sub).top(limit=lim)
if type.startswith("top")
else reddit.subreddit(sub).new(limit=lim)
if type.startswith("new")
else reddit.subreddit(sub).hot(limit=lim)
if type.startswith("hot")
else reddit.subreddit(sub).rising(limit=lim)
if type.startswith("rising")
else reddit.subreddit(sub).controversial(limit=lim)
if type.startswith("controversial")
else reddit.subreddit(sub).gilded(limit=lim)
if type.startswith("gilded")
else []
)
if type.endswith("nth"):
submission_list = [list(submission_list)[lim - 1]]
for submission in submission_list:
if len(submission.selftext) <= 2000:
embed = discord.Embed(
title=submission.title, description=submission.selftext
)
else:
embed = discord.Embed(
title=submission.title,
description="That post is way too long and I'm not typing out all of it, here's a link - "
+ submission.shortlink,
)
imgFlag = not submission.is_self
if imgFlag:
embed.set_image(url=submission.url)
print(submission.shortlink)
await message.channel.send(embed=embed)
# TicTacToe
global TheBoard
X = 1
O = -1
M = 0
whee = ""
end = False
intro = "Tic Tac Toe board initialized \n start messages directly with $move, and enter move as follows \n use 1, 2, 3, 4, 5 ... \n or 11, 12, 13, 21, 22 ..."
if message.content.startswith("$tictactoe"):
TheBoard = TTTAI.ini_board()
await message.channel.send(intro)
if message.content.startswith("$move"):
user = message.content[6:8]
p, q = PlayTTT.conv(int(user))
if not PlayTTT.canplay(copy.deepcopy(TheBoard), p, q):
await message.channel.send("Illegal")
return
TheBoard[p][q] = X
end = TTTAI.terminal(copy.deepcopy(TheBoard))
if end:
embed = discord.Embed(
title="Tic Tac Toe",
description=" " + PlayTTT.dispdiscy(copy.deepcopy(TheBoard)),
)
embed.colour = random.randint(0, 16777215)
await message.channel.send(embed=embed)
winner = TTTAI.winner(TheBoard)
if winner == X:
whee = "X wins"
elif winner == O:
whee = "O wins"
else:
whee = "Tie"
await message.channel.send(whee)
return
AI = random.choice(TTTAI.minimax(copy.deepcopy(TheBoard)))
p = AI[0]
q = AI[1]
TheBoard[p][q] = O
print(PlayTTT.dispdiscy(copy.deepcopy(TheBoard)))
end = TTTAI.terminal(copy.deepcopy(TheBoard))
if end:
embed = discord.Embed(
title="Tic Tac Toe",
description=" " + PlayTTT.dispdiscy(copy.deepcopy(TheBoard)),
)
embed.colour = random.randint(0, 16777215)
await message.channel.send(embed=embed)
winner = TTTAI.winner(TheBoard)
if winner == X:
whee = "X wins"
elif winner == O:
whee = "O wins"
else:
whee = "Tie"
await message.channel.send(whee)
return
embed = discord.Embed(
title="Tic Tac Toe",
description=" " + PlayTTT.dispdiscy(copy.deepcopy(TheBoard)),
)
embed.colour = random.randint(0, 16777215)
await message.channel.send(embed=embed)
@client.event
async def on_ready():
print(f"{client.user} has connected to {client.guilds[0].name}!")
client.run(TOKEN)