forked from rstad/wordlebridge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
165 lines (156 loc) · 8.1 KB
/
main.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
import os
import re
import discord
from dotenv import load_dotenv
load_dotenv()
BOT_TOKEN = os.getenv("BOT_TOKEN")
rex = re.compile(r'Wordle [0-9]{3,}')
botrex = re.compile(r'WordleBot\nSkill')
fivegreens = "🟩🟩🟩🟩🟩"
padline = "❌❌❌❌❌"
intents = discord.Intents.default()
intents.message_content = True
intents.members = True
client = discord.Client(intents=intents)
def get_server_nick(server,author):
try:
member = server.get_member(author.id)
if member.display_name:
return member.display_name
else:
return author.name
except:
return author.name
def transform_message(message):
if re.search(rex,message).start() == 0: # no starting word, straight wordle paste
if re.search(fivegreens,message) != None: # not X/6
if re.search(botrex,message) != None: # has wordlebot scores
formatted_message = ""
header = message.split('\n')[0]
slindex = header.find("/")
formatted_message += header[:slindex-2]+" ||"+header[slindex-1]+"||"+header[slindex:]+'\n\n'
formatted_message += "||"+re.split(rex,message)[1].split('\n\n')[1].split(fivegreens)[0]
formatted_message += fivegreens+"\n"
for i in range(5-len(re.split(rex,message)[1].split('\n\n')[1].split(fivegreens)[0].strip().split('\n'))):
formatted_message+=padline+'\n'
formatted_message += '||\nWordleBot\n'
formatted_message += re.split(rex,message)[1].split('\n\nWordleBot\n')[1]
return formatted_message
else: # straight paste, solved, no wordlebot
formatted_message = ""
header = message.split('\n')[0]
slindex = header.find("/")
formatted_message += header[:slindex-2]+" ||"+header[slindex-1]+"||"+header[slindex:]+'\n\n'
formatted_message += "||"+re.split(rex,message)[1].split('\n\n')[1].split(fivegreens)[0]
formatted_message += fivegreens+"\n"
for i in range(5-len(re.split(rex,message)[1].split('\n\n')[1].split(fivegreens)[0].strip().split('\n'))):
formatted_message+=padline+'\n'
formatted_message = formatted_message.strip()
formatted_message += re.split(rex,message)[1].split('\n\n')[1].split(fivegreens)[1]+"||"
return formatted_message
else: # straight paste, failed
if re.search(botrex,message) != None: # has wordlebot scores
formatted_message = ""
header = message.split('\n')[0]
slindex = header.find("/")
formatted_message += header[:slindex-2]+" ||"+header[slindex-1]+"||"+header[slindex:]+'\n\n'
formatted_message += "||"+re.split(rex,message)[1].split('\n\n')[1]+"||"
formatted_message += '\n\nWordleBot\n'
formatted_message += re.split(rex,message)[1].split('\n\nWordleBot\n')[1]
return formatted_message
else: # no wordlebot score, straight paste, failed
formatted_message = ""
header = message.split('\n')[0]
slindex = header.find("/")
formatted_message += header[:slindex-2]+" ||"+header[slindex-1]+"||"+header[slindex:]+'\n\n'
formatted_message += "||"+re.split(rex,message)[1].split('\n\n')[1]+"||"
return formatted_message
else: # has a leading word
if re.search(fivegreens,message) != None: # not X/6
if re.search(botrex,message) != None: # has wordlebot scores
formatted_message = re.split(rex,message)[0].strip().upper()+'\n'
header = message.split('\n')[0]
slindex = header.find("/")
windex = header.find("Wordle")
formatted_message += header[windex:slindex-2]+" ||"+header[slindex-1]+"||"+header[slindex:]+'\n\n'
formatted_message += "||"+re.split(rex,message)[1].split('\n\n')[1].split(fivegreens)[0]
formatted_message += fivegreens+"\n"
for i in range(5-len(re.split(rex,message)[1].split('\n\n')[1].split(fivegreens)[0].strip().split('\n'))):
formatted_message+=padline+'\n'
formatted_message += '||\nWordleBot\n'
formatted_message += re.split(rex,message)[1].split('\n\nWordleBot\n')[1]
return formatted_message
else:
formatted_message = re.split(rex,message)[0].strip().upper()+'\n'
header = message.split('\n')[0]
slindex = header.find("/")
windex = header.find("Wordle")
formatted_message += header[windex:slindex-2]+" ||"+header[slindex-1]+"||"+header[slindex:]+'\n\n'
formatted_message += "||"+re.split(rex,message)[1].split('\n\n')[1]+'\n'
for i in range(5-len(re.split(rex,message)[1].split('\n\n')[1].split(fivegreens)[0].strip().split('\n'))):
formatted_message+=padline+'\n'
formatted_message = formatted_message.strip()+"||"
return formatted_message
else:
if re.search(botrex,message) != None: # has wordlebot scores
formatted_message = re.split(rex,message)[0].strip().upper()+'\n'
header = message.split('\n')[0]
slindex = header.find("/")
windex = header.find("Wordle")
formatted_message += header[windex:slindex-2]+" ||"+header[slindex-1]+"||"+header[slindex:]+'\n\n'
formatted_message += "||"+re.split(rex,message)[1].split('\n\n')[1]+"||"
formatted_message += '\n\nWordleBot\n'
formatted_message += re.split(rex,message)[1].split('\n\nWordleBot\n')[1]
return formatted_message
else: # failed, so no padding
formatted_message = re.split(rex,message)[0].strip().upper()+'\n'
header = message.split('\n')[0]
slindex = header.find("/")
windex = header.find("Wordle")
formatted_message += header[windex:slindex-2]+" ||"+header[slindex-1]+"||"+header[slindex:]+'\n\n'
formatted_message += "||"+re.split(rex,message)[1].split('\n\n')[1]+"||"
return formatted_message
def is_wordle_message(message):
if re.search(rex,str(message)):
return True
else:
return False
@client.event
async def on_ready():
print(f'We have logged in as {client.user}')
@client.event
async def on_message(message):
if message.author == client.user: #ignore self messages
return
#print(str(message.content))
if is_wordle_message(message.content):
print("is wordle message")
formatted_message = transform_message(message.content)
fmh_wordle = client.get_channel(1064641280791019623)
rta_general = client.get_channel(692795745409171589)
rta_guild = client.get_guild(692795745409171586)
print(message)
print(message.content)
print(get_server_nick(rta_guild,message.author))
print(formatted_message)
if not message.guild: # is DM?
try:
await rta_general.send(get_server_nick(rta_guild,message.author)+" "+formatted_message)
await fmh_wordle.send(get_server_nick(rta_guild,message.author)+" "+formatted_message)
except discord.errors.Forbidden:
pass
else: # not DM
if message.channel.id == 1064641280791019623: #fmh wordle
try:
await rta_general.send(get_server_nick(rta_guild,message.author)+" "+formatted_message)
except discord.errors.Forbidden:
pass
if message.channel.id == 692795745409171589: #rt2a general
try:
await fmh_wordle.send(get_server_nick(rta_guild,message.author)+" "+formatted_message)
except discord.errors.Forbidden:
pass
else:
print("not wordle message")
pass
client.run(BOT_TOKEN)