-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
executable file
·126 lines (109 loc) · 3.53 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
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env python3
import discord as ds
import os
import sys
import random
import datetime
with open('token') as f:
TOKEN = f.read().strip()
CHANNELS = ('bot-tester', 'wordlelikes')
with open('wordlist') as f:
WORD_LIST = f.read().split(' ')
# WORD = 'qwerty'
def new_word():
global WORD
global START_TIME
WORD = random.choice(WORD_LIST)
START_TIME = datetime.datetime.now().strftime('%B %d, %Y %H:%M %p')
print(f'new word is {WORD}')
print(f'start time is {START_TIME}')
reset_guesslist()
def reset_guesslist():
global GUESS_LIST
GUESS_LIST = ''
def add_to_guesslist(guess, author):
global GUESS_LIST
if GUESS_LIST != '':
GUESS_LIST += '\n'
GUESS_LIST += guess + ' – ' + author
# new_word()
# print(WORD)
# sys.exit()
GUESS_LIST = ''
# add any "intents" (discord permissions we want) here
intents = ds.Intents.default()
intents.message_content = True
client = ds.Client(intents=intents)
# event listeners
@client.event
async def on_ready():
print(f'We have logged in as {client.user}')
print(f'Accessing servers {[g.name for g in client.guilds]}')
print(f'Reading messages in #{CHANNELS}')
new_word()
@client.event
async def on_message(message):
# ignore these messages
if message.author == client.user:
return
if message.channel.name not in CHANNELS:
return
# fun chatter
if message.content == '!hello':
await message.channel.send(f'Hello {message.author.mention}!')
return
if message.content in ('$help','$info', '$rules', '!help', '!info', '!rules'):
await message.channel.send('I am but a humble botto, pls don\'t expect too much of me.')
return
# ignore these too
if not message.content.startswith('!') or len(message.content) != 7:
return
# game content starts here
if message.content.startswith('!') and message.content[1:] not in WORD_LIST:
await message.channel.send('Not a valid word nope!')
return
if message.content[1:].lower() == WORD:
await message.channel.send(f'**{WORD.upper()}** – you got it, yay!✨')
# reset game here
new_word()
await message.channel.send('okay, new game!')
return
if message.content.startswith('!'):
guess = wordle_logic(message)
add_to_guesslist(guess, message.author.name)
print(f'{message.author} guessed {guess}')
await message.channel.send(GUESS_LIST)
# def formatted_update():
#
#
# return msg
def wordle_logic(message):
guess = message.content[1:].lower()
guess_status = [0]*6
word_left = WORD
# check for greens
for i in range(6):
if guess[i] == WORD[i]:
# response += '**' + guess[i] + '**'
guess_status[i] = 2
word_left = word_left[:i] + '0' + word_left[i+1:]
# check for yellows
for i in range(6):
if guess[i] in word_left and guess_status[i] == 0:
# response += guess[i]
guess_status[i] = 1
j = word_left.find(guess[i])
word_left = word_left[:j] + '0' + word_left[j+1:]
# construct response
response = ''
for i in range(6):
if guess_status[i] == 0:
response += guess[i].lower()
elif guess_status[i] == 1:
response += guess[i].upper()
elif guess_status[i] == 2:
response += '**' + guess[i].upper() + '**'
# remove instances of **** from response so bolding works
response = ''.join(response.split('****'))
return response
client.run(TOKEN)