forked from hypogirl/collable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollable.py
118 lines (101 loc) · 4.51 KB
/
collable.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
import discord
import asyncio
from discord.ext import commands
from re import sub
intents = discord.Intents().all()
bot = commands.Bot(command_prefix='!', intents=intents)
bot.remove_command('help') #removing the default help command
channel = role = embed = embed_message = artist = None
index = 0
full_squares = ""
@bot.event
async def on_ready():
print("Connected\n")
@bot.command()
async def select(ctx, *, arg):
if ctx.message.author.id != 455301777055547394:
return
global channel, role
args = arg.split()
channel = bot.get_channel(int(args[0]))
role = ctx.guild.get_role(int(args[1]))
await ctx.send(f"{channel.mention} and \"@{role.name}\" selected.")
@bot.command()
async def start(ctx, *, arg):
if ctx.message.author.id != 455301777055547394:
return
global channel, embed, embed_message, artist
artist = arg.upper()
blanks = sub(r"\w","_ ",artist)
blanks = sub(r" "," ",blanks)
embed_title = discord.Embed(title="HEALTH COLLABLE", description= " ", color= 0xff0000)
embed = discord.Embed(title="GUESS A COLLABORATION FROM DISCO4 :: PART II", description=f"Type the name of the artist```{blanks}```", color=0xff0000)
await channel.send(embed= embed_title)
embed_message = await channel.send(embed= embed)
def check_word(guess, artist):
print(guess, artist)
visited = dict()
green = "🟩"
yellow = "🟨"
black = "⬛"
guess_split = guess.split()
artist_split = artist.split()
squares = list()
for guess_word, artist_word in zip(guess_split, artist_split):
if len(guess_word) != len(artist_word):
return "error"
for guess_word, artist_word in zip(guess_split, artist_split):
visited_aux, squares_word = zip(*[((letter,artist_word.count(letter) - 1), green) if letter == real_letter else ((letter,artist_word.count(letter)), black) for letter, real_letter in zip(guess_word, artist_word)])
visited_aux = list(visited_aux)
squares_word = list(squares_word)
for letter,count in visited_aux:
if letter not in visited:
visited[letter] = count
for i, (letter, real_letter) in enumerate(zip(guess_word, artist_word)):
if letter == real_letter:
continue
if letter in artist and visited[letter] > 0:
squares_word[i] = yellow
visited[letter] -= 1
squares.append(str().join(squares_word))
return ' '.join(squares)
@bot.event
async def on_message(message):
if message.author == bot.user:
return
if message.content.startswith("!"):
await bot.process_commands(message)
return
global channel, role, embed, index, embed_message, artist, full_squares
if channel and message.channel == channel:
error_embed = discord.Embed(title="Please enter the correct number of characters.", description= " ")
if len(message.content) != len(artist):
error_embed = discord.Embed(title="Please enter the correct number of characters.")
error_message = await channel.send(embed= error_embed)
await message.delete()
await asyncio.sleep(3)
await error_message.delete()
else:
index += 1
if index > 6:
await channel.send("WRONG ARTIST NAME. SEE YOU NEXT TIME.")
await message.author.remove_roles(role)
else:
squares = check_word(message.content.upper(), artist)
if squares != "error":
full_squares += squares + "\n"
embed.add_field(name=squares, value=message.content.upper(), inline=False)
await embed_message.edit(embed= embed)
if "🟨" not in squares and "⬛" not in squares:
full_squares = full_squares.replace(" ",".")
full_squares = full_squares.replace(" ","")
full_squares = full_squares.replace("."," ")
success_embed = discord.Embed(title="YOU DID A HEALTH OF A JOB", description=f"COLLABLE 2 {str(index)}/6\n\n{full_squares}")
await channel.send(embed= success_embed)
await message.author.remove_roles(role)
else:
error_message = await channel.send(embed= error_embed)
await message.delete()
await asyncio.sleep(3)
await error_message.delete()
bot.run("bot-token")