-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbigBot.cc
More file actions
84 lines (67 loc) · 3.39 KB
/
bigBot.cc
File metadata and controls
84 lines (67 loc) · 3.39 KB
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
#include <dpp/dpp.h>
#include <iostream>
#include <random>
#include <utility>
#include <unordered_set>
#include <vector>
#include "game.h"
using namespace std;
int main(){
// stores user values in struct defined in game.h
unique_ptr<Dictionary> dictionary = make_unique<Dictionary>();
unordered_map<dpp::snowflake, GameState> games;
// command to run: export WORDLE_TOKEN="$(cat secret)"
const char *token = getenv("WORDLE_TOKEN");
if (!token) {
cout << "Empty token." << endl;
return 1;
}
dpp::cluster bot(token);
bot.on_ready([&bot](const auto & event) {
cout << "Logged in as " << bot.me.username << "!\n";
});
dictionary = ReadDictionary();
bot.on_message_create([&bot, &games, &dictionary](const auto& event) {
const dpp::snowflake user = event.msg.author.id;
if(event.msg.author.username == "wordle-cutecatfann"){ return; }
if (event.msg.content == "!play") {
dictionary = ReadDictionary();
bot.message_create(dpp::message(event.msg.channel_id, "Welcome to Wordle Bot! The game has now begun... Will you suceed? Type your guesses, or !quit to end the game. "));
bot.message_create(dpp::message(event.msg.channel_id, "Key: :green_square: = you got the letter, :yellow_square: = it's in the word but wrong position, :red_square: = not in the word"));
bot.message_create(dpp::message(event.msg.channel_id, "Enter a real word that is five letters long: "));
InitGame(games, user, dictionary);
} else if (event.msg.content == "!quit"){
bot.message_create(dpp::message(event.msg.channel_id, "Sorry to see you go, come back soon!"));
games.erase(user);
} else {
string guess = event.msg.content;
string winner = Guess(user, guess, games, dictionary);
games[user].guesses.push_back(winner);
if(winner.find("word") != std::string::npos){
bot.message_create(dpp::message(event.msg.channel_id, winner));
games[user].guesses.pop_back();
}
if(games[user].guesses.size() == 6){
for (int j = 0; j < games[user].guesses.size(); j++){
bot.message_create(dpp::message(event.msg.channel_id, games[user].guesses[j]));
}
bot.message_create(dpp::message(event.msg.channel_id, "Oh no! You lost! :smirk_cat: The correct word was"));
bot.message_create(dpp::message(event.msg.channel_id, games[user].word));
bot.message_create(dpp::message(event.msg.channel_id, "Better luck next time! If you would like to play again, type !play"));
games.erase(user);
} else {
for (int j = 0; j < games[user].guesses.size(); j++){
bot.message_create(dpp::message(event.msg.channel_id, games[user].guesses[j]));
}
int n = count(winner.begin(), winner.end(), 'g');
if(n == 5){
bot.message_create(dpp::message(event.msg.channel_id, "You won! Good job! :star_struck: :clap:"));
bot.message_create(dpp::message(event.msg.channel_id, "To play again, just type !play "));
games.erase(user);
}
}
}
});
bot.start(false);
return 0;
}