diff --git a/.gitignore b/.gitignore index f554038..cc4d9c4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,38 +1,2 @@ -### --- Python -# virtualenv -*venv* -bin/ -include/ -lib/ -local/ .DS_Store -secrets* -*.pyc -*.log -nohup.out -__pycache__ -.pytest_cache -.cache -job_manager.db -### --- Golang -# If you prefer the allow list template instead of the deny list, see community template: -# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore -# -# Binaries for programs and plugins -*.exe -*.exe~ -*.dll -*.so -*.dylib - -# Test binary, built with `go test -c` -*.test - -# Output of the go coverage tool, specifically when used with LiteIDE -*.out - -# Dependency directories (remove the comment below to include it) -# vendor/ - -# Go workspace file -config.json \ No newline at end of file +secrets* \ No newline at end of file diff --git a/common/discordclient.py b/archive/discordclient-common.py similarity index 100% rename from common/discordclient.py rename to archive/discordclient-common.py diff --git a/assets-discord/Annette/Annette_Preview.png b/assets-discord/Annette/Annette_Preview.png new file mode 100644 index 0000000..868b069 Binary files /dev/null and b/assets-discord/Annette/Annette_Preview.png differ diff --git a/assets-discord/Annette/Annette_Quotes.txt b/assets-discord/Annette/Annette_Quotes.txt new file mode 100644 index 0000000..92801de --- /dev/null +++ b/assets-discord/Annette/Annette_Quotes.txt @@ -0,0 +1,4 @@ +I bring joy! +Let's have some fun! +Sing with me! +Here, a gift! \ No newline at end of file diff --git a/assets-discord/Artur/Artur_Preview.png b/assets-discord/Artur/Artur_Preview.png new file mode 100644 index 0000000..5e3c997 Binary files /dev/null and b/assets-discord/Artur/Artur_Preview.png differ diff --git a/assets-discord/Artur/Artur_Quotes.txt b/assets-discord/Artur/Artur_Quotes.txt new file mode 100644 index 0000000..2cd5f09 --- /dev/null +++ b/assets-discord/Artur/Artur_Quotes.txt @@ -0,0 +1,4 @@ +Blessed night! +I've put my heart into this. +Just for you. +It's snowing. \ No newline at end of file diff --git a/assets-discord/BlackKnight/ABS_BlackKnight_Preview.png b/assets-discord/BlackKnight/ABS_BlackKnight_Preview.png new file mode 100644 index 0000000..acd7451 Binary files /dev/null and b/assets-discord/BlackKnight/ABS_BlackKnight_Preview.png differ diff --git a/assets-discord/BlackKnight/BlackKnight_Preview.png b/assets-discord/BlackKnight/BlackKnight_Preview.png new file mode 100644 index 0000000..feaa65f Binary files /dev/null and b/assets-discord/BlackKnight/BlackKnight_Preview.png differ diff --git a/assets-discord/BlackKnight/BlackKnight_Quotes.txt b/assets-discord/BlackKnight/BlackKnight_Quotes.txt new file mode 100644 index 0000000..565cc5a --- /dev/null +++ b/assets-discord/BlackKnight/BlackKnight_Quotes.txt @@ -0,0 +1,4 @@ +The winter festival is upon us. +For the holiday. +The night is still. +Are you the praying type? \ No newline at end of file diff --git a/assets-discord/Bruno/Bruno_Preview.png b/assets-discord/Bruno/Bruno_Preview.png new file mode 100644 index 0000000..a3f04f7 Binary files /dev/null and b/assets-discord/Bruno/Bruno_Preview.png differ diff --git a/assets-discord/Bruno/Bruno_Quotes.txt b/assets-discord/Bruno/Bruno_Quotes.txt new file mode 100644 index 0000000..2125665 --- /dev/null +++ b/assets-discord/Bruno/Bruno_Quotes.txt @@ -0,0 +1,4 @@ +What a festival it is! +The winter's blessing. +A gift. Here! +Hasten your slumber! \ No newline at end of file diff --git a/assets-discord/Cordelia/Cordelia_Preview.png b/assets-discord/Cordelia/Cordelia_Preview.png new file mode 100644 index 0000000..90879aa Binary files /dev/null and b/assets-discord/Cordelia/Cordelia_Preview.png differ diff --git a/assets-discord/Cordelia/Cordelia_Quotes.txt b/assets-discord/Cordelia/Cordelia_Quotes.txt new file mode 100644 index 0000000..15771fa --- /dev/null +++ b/assets-discord/Cordelia/Cordelia_Quotes.txt @@ -0,0 +1,4 @@ +Duo: It's a beautiful night! +Duo: "It's time!" "I know!" +Cordelia: Got something for you. +Selena: I hope you're happy... \ No newline at end of file diff --git a/assets-discord/Dorothea/Dorothea_Preview.png b/assets-discord/Dorothea/Dorothea_Preview.png new file mode 100644 index 0000000..e015ab9 Binary files /dev/null and b/assets-discord/Dorothea/Dorothea_Preview.png differ diff --git a/assets-discord/Dorothea/Dorothea_Quotes.txt b/assets-discord/Dorothea/Dorothea_Quotes.txt new file mode 100644 index 0000000..0681702 --- /dev/null +++ b/assets-discord/Dorothea/Dorothea_Quotes.txt @@ -0,0 +1,4 @@ +The stars twinkle above… +Sing along! +This'll be fun. +Just for you! \ No newline at end of file diff --git a/assets-discord/Lysithea/Lysithea_Preview.png b/assets-discord/Lysithea/Lysithea_Preview.png new file mode 100644 index 0000000..570e2f3 Binary files /dev/null and b/assets-discord/Lysithea/Lysithea_Preview.png differ diff --git a/assets-discord/Lysithea/Lysithea_Quotes.txt b/assets-discord/Lysithea/Lysithea_Quotes.txt new file mode 100644 index 0000000..b2fc99b --- /dev/null +++ b/assets-discord/Lysithea/Lysithea_Quotes.txt @@ -0,0 +1,4 @@ +Duo: We're just that good! +Duo: A gift! Be grateful. +Lysithea: This is for you! +Lute: Have a pleasant eve. \ No newline at end of file diff --git a/assets-discord/Mirabilis/Mirabilis_Preview.png b/assets-discord/Mirabilis/Mirabilis_Preview.png new file mode 100644 index 0000000..b29bf3c Binary files /dev/null and b/assets-discord/Mirabilis/Mirabilis_Preview.png differ diff --git a/assets-discord/Mirabilis/Mirabilis_Quotes.txt b/assets-discord/Mirabilis/Mirabilis_Quotes.txt new file mode 100644 index 0000000..5c0b0d6 --- /dev/null +++ b/assets-discord/Mirabilis/Mirabilis_Quotes.txt @@ -0,0 +1,4 @@ +Yay, festival... +A gift for you... +Are we having fun yet? +Nap time... \ No newline at end of file diff --git a/assets/Annette/Annette_Preview.png b/assets/Annette/Annette_Preview.png index 3fa30f3..868b069 100644 Binary files a/assets/Annette/Annette_Preview.png and b/assets/Annette/Annette_Preview.png differ diff --git a/assets/Annette/Annette_Quotes.txt b/assets/Annette/Annette_Quotes.txt index 0d4ee18..92801de 100644 --- a/assets/Annette/Annette_Quotes.txt +++ b/assets/Annette/Annette_Quotes.txt @@ -1,4 +1,4 @@ -I'm not gonna lose! -Get lost! -I'll show you! -I can help too! \ No newline at end of file +I bring joy! +Let's have some fun! +Sing with me! +Here, a gift! \ No newline at end of file diff --git a/assets/Artur/Artur_Preview.png b/assets/Artur/Artur_Preview.png new file mode 100644 index 0000000..5e3c997 Binary files /dev/null and b/assets/Artur/Artur_Preview.png differ diff --git a/assets/Artur/Artur_Quotes.txt b/assets/Artur/Artur_Quotes.txt new file mode 100644 index 0000000..2cd5f09 --- /dev/null +++ b/assets/Artur/Artur_Quotes.txt @@ -0,0 +1,4 @@ +Blessed night! +I've put my heart into this. +Just for you. +It's snowing. \ No newline at end of file diff --git a/assets/BlackKnight/BlackKnight_Preview.png b/assets/BlackKnight/BlackKnight_Preview.png index 4e3e3e2..6e52ea1 100644 Binary files a/assets/BlackKnight/BlackKnight_Preview.png and b/assets/BlackKnight/BlackKnight_Preview.png differ diff --git a/assets/BlackKnight/BlackKnight_Quotes.txt b/assets/BlackKnight/BlackKnight_Quotes.txt index 6b89208..565cc5a 100644 --- a/assets/BlackKnight/BlackKnight_Quotes.txt +++ b/assets/BlackKnight/BlackKnight_Quotes.txt @@ -1,4 +1,4 @@ -Know your place. -Will you survive? -Fool. -Give your all. +The winter festival is upon us. +For the holiday. +The night is still. +Are you the praying type? \ No newline at end of file diff --git a/assets/BlackKnight/Black_Knight_Quotes.txt b/assets/BlackKnight/Black_Knight_Quotes.txt deleted file mode 100644 index e0b5159..0000000 --- a/assets/BlackKnight/Black_Knight_Quotes.txt +++ /dev/null @@ -1,4 +0,0 @@ -Know your place. -Will you survive? -Fool. -Give your all. \ No newline at end of file diff --git a/assets/Bruno/Bruno_Preview.png b/assets/Bruno/Bruno_Preview.png new file mode 100644 index 0000000..a3f04f7 Binary files /dev/null and b/assets/Bruno/Bruno_Preview.png differ diff --git a/assets/Bruno/Bruno_Quotes.txt b/assets/Bruno/Bruno_Quotes.txt new file mode 100644 index 0000000..2125665 --- /dev/null +++ b/assets/Bruno/Bruno_Quotes.txt @@ -0,0 +1,4 @@ +What a festival it is! +The winter's blessing. +A gift. Here! +Hasten your slumber! \ No newline at end of file diff --git a/assets/Cordelia/Cordelia_Preview.png b/assets/Cordelia/Cordelia_Preview.png new file mode 100644 index 0000000..90879aa Binary files /dev/null and b/assets/Cordelia/Cordelia_Preview.png differ diff --git a/assets/Cordelia/Cordelia_Quotes.txt b/assets/Cordelia/Cordelia_Quotes.txt new file mode 100644 index 0000000..15771fa --- /dev/null +++ b/assets/Cordelia/Cordelia_Quotes.txt @@ -0,0 +1,4 @@ +Duo: It's a beautiful night! +Duo: "It's time!" "I know!" +Cordelia: Got something for you. +Selena: I hope you're happy... \ No newline at end of file diff --git a/assets/Dorothea/Dorothea_Preview.png b/assets/Dorothea/Dorothea_Preview.png index 4fc44e9..e015ab9 100644 Binary files a/assets/Dorothea/Dorothea_Preview.png and b/assets/Dorothea/Dorothea_Preview.png differ diff --git a/assets/Dorothea/Dorothea_Quotes.txt b/assets/Dorothea/Dorothea_Quotes.txt index 23ab09a..0681702 100644 --- a/assets/Dorothea/Dorothea_Quotes.txt +++ b/assets/Dorothea/Dorothea_Quotes.txt @@ -1,4 +1,4 @@ -Duo: A curse on you! -Duo: Let's give them a show. Yeah! -Dorothea: All eyes on us! -Lene: Watch your step! \ No newline at end of file +The stars twinkle above… +Sing along! +This'll be fun. +Just for you! \ No newline at end of file diff --git a/assets/Lysithea/Lysithea_Preview.png b/assets/Lysithea/Lysithea_Preview.png index c946098..570e2f3 100644 Binary files a/assets/Lysithea/Lysithea_Preview.png and b/assets/Lysithea/Lysithea_Preview.png differ diff --git a/assets/Lysithea/Lysithea_Quotes.txt b/assets/Lysithea/Lysithea_Quotes.txt index 2e17359..b2fc99b 100644 --- a/assets/Lysithea/Lysithea_Quotes.txt +++ b/assets/Lysithea/Lysithea_Quotes.txt @@ -1,4 +1,4 @@ -Begone! -Don't waste my time! -Did you think I'd miss? -Die with your regrets. \ No newline at end of file +Duo: We're just that good! +Duo: A gift! Be grateful. +Lysithea: This is for you! +Lute: Have a pleasant eve. \ No newline at end of file diff --git a/assets/Mirabilis/Mirabilis_Preview.png b/assets/Mirabilis/Mirabilis_Preview.png new file mode 100644 index 0000000..b29bf3c Binary files /dev/null and b/assets/Mirabilis/Mirabilis_Preview.png differ diff --git a/assets/Mirabilis/Mirabilis_Quotes.txt b/assets/Mirabilis/Mirabilis_Quotes.txt new file mode 100644 index 0000000..5c0b0d6 --- /dev/null +++ b/assets/Mirabilis/Mirabilis_Quotes.txt @@ -0,0 +1,4 @@ +Yay, festival... +A gift for you... +Are we having fun yet? +Nap time... \ No newline at end of file diff --git a/bots/README.md b/bots/README.md new file mode 100644 index 0000000..171298a --- /dev/null +++ b/bots/README.md @@ -0,0 +1,6 @@ +# Lists of Bots +* Convoy - Python API for Gauntlet Scores +* Genny - Python Discord Bot for Twitter Alerts +* Golembane - Golang API for Database Updates +* Rebecca - Python Discord Bot for Discord Alerts +* Robin - Golang Discord Bot for Database Updates \ No newline at end of file diff --git a/bots/convoy/.gitignore b/bots/convoy/.gitignore new file mode 100644 index 0000000..f554038 --- /dev/null +++ b/bots/convoy/.gitignore @@ -0,0 +1,38 @@ +### --- Python +# virtualenv +*venv* +bin/ +include/ +lib/ +local/ +.DS_Store +secrets* +*.pyc +*.log +nohup.out +__pycache__ +.pytest_cache +.cache +job_manager.db +### --- Golang +# If you prefer the allow list template instead of the deny list, see community template: +# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore +# +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +# Go workspace file +config.json \ No newline at end of file diff --git a/convoy/Dockerfile b/bots/convoy/Dockerfile similarity index 100% rename from convoy/Dockerfile rename to bots/convoy/Dockerfile diff --git a/convoy/Pipfile b/bots/convoy/Pipfile similarity index 100% rename from convoy/Pipfile rename to bots/convoy/Pipfile diff --git a/convoy/Pipfile.lock b/bots/convoy/Pipfile.lock similarity index 100% rename from convoy/Pipfile.lock rename to bots/convoy/Pipfile.lock diff --git a/convoy/api.py b/bots/convoy/api.py similarity index 100% rename from convoy/api.py rename to bots/convoy/api.py diff --git a/convoy/assets_check.py b/bots/convoy/assets_check.py similarity index 100% rename from convoy/assets_check.py rename to bots/convoy/assets_check.py diff --git a/bots/convoy/assets_check_discord.py b/bots/convoy/assets_check_discord.py new file mode 100644 index 0000000..e3f8f7d --- /dev/null +++ b/bots/convoy/assets_check_discord.py @@ -0,0 +1,19 @@ +from config import * # current VG particpants and round dates + +print("Hello world!") +units = [vg_unit_1, vg_unit_2, vg_unit_3, vg_unit_4, vg_unit_5, vg_unit_6, vg_unit_7, vg_unit_8] +for unit in units: + print('Testing %s' % unit) + quote_url = "./assets-discord/%s/%s_Quotes.txt" % (unit, unit) + quotes = open(quote_url).read().splitlines() + print("~~~") + print(quotes[0]) + print(quotes[1]) + print(quotes[2]) + print(quotes[3]) + print("~~~") + img_url = "./assets-discord/%s/%s_Preview.png" % (unit, unit) + fd = open(img_url, 'r') + # pngdata = fd.read() + fd.close() + print('Assets of %s successfully opened' % unit) diff --git a/convoy/config.py b/bots/convoy/config.py similarity index 71% rename from convoy/config.py rename to bots/convoy/config.py index e809c07..7298257 100644 --- a/convoy/config.py +++ b/bots/convoy/config.py @@ -1,22 +1,22 @@ # UTC is 8 Hours Ahead PST vg_assets_root_path="assets" -vg_hashtag='#ND' +vg_hashtag='#SF!' vg_test=False -vg_url='https://support.fire-emblem-heroes.com/voting_gauntlet/tournaments/66' -round_1_start_raw = 'Dec 01 2022 7:00AM' -round_1_end_raw = 'Dec 03 2022 4:00AM' -round_2_start_raw = 'Dec 03 2022 7:00AM' -round_2_end_raw = 'Dec 05 2022 4:00AM' -round_3_start_raw = 'Dec 05 2022 7:00AM' -round_3_end_raw = 'Dec 07 2022 4:00AM' -vg_unit_1 = "Camilla" -vg_unit_2 = "Laegjarn" -vg_unit_3 = "Igrene" -vg_unit_4 = "Shinon" -vg_unit_5 = "Shamir" -vg_unit_6 = "Cherche" -vg_unit_7 = "Haar" -vg_unit_8 = "Heath" +vg_url='https://support.fire-emblem-heroes.com/voting_gauntlet/tournaments/67' +round_1_start_raw = 'Dec 26 2022 7:00AM' +round_1_end_raw = 'Dec 28 2022 4:00AM' +round_2_start_raw = 'Dec 28 2022 7:00AM' +round_2_end_raw = 'Dec 30 2022 4:00AM' +round_3_start_raw = 'Dec 30 2022 7:00AM' +round_3_end_raw = 'Jan 01 2023 4:00AM' +vg_unit_1 = "Lysithea" +vg_unit_2 = "Cordelia" +vg_unit_3 = "Artur" +vg_unit_4 = "Mirabilis" +vg_unit_5 = "BlackKnight" +vg_unit_6 = "Bruno" +vg_unit_7 = "Dorothea" +vg_unit_8 = "Annette" discord_channel_ids = { vg_unit_1 : 783177258713874443, vg_unit_2 : 783177296646897665, diff --git a/bots/convoy/docker-compose.yml b/bots/convoy/docker-compose.yml new file mode 100644 index 0000000..86b4f9e --- /dev/null +++ b/bots/convoy/docker-compose.yml @@ -0,0 +1,17 @@ +version: "3.8" +services: + convoy: + build: . + container_name: convoy + # image: atemosta/feh-gauntlet-bot:convoy-latest + command: uvicorn api:app --host 0.0.0.0 --port 5057 --reload + restart: unless-stopped + networks: + - feh-vg-bot + ports: + - 5057:5057 + volumes: + - ../../assets:/app/assets +networks: + feh-vg-bot: + external: true \ No newline at end of file diff --git a/convoy/gauntlet_template.py b/bots/convoy/gauntlet_template.py similarity index 82% rename from convoy/gauntlet_template.py rename to bots/convoy/gauntlet_template.py index 28e788b..4854c24 100644 --- a/convoy/gauntlet_template.py +++ b/bots/convoy/gauntlet_template.py @@ -13,8 +13,6 @@ # main method (called every 30 minutes) def get_unit_scores(): - # Set Up Logger - # logger = set_up_logger("gauntlet_template") # Use mechanize to set the locale's select value to 'en-US' br = mechanize.Browser() @@ -37,7 +35,7 @@ def get_unit_scores(): # Use BeautifulSoup to parse the response r = br.response().read() soup = BeautifulSoup(r, 'html.parser') - #logger.debug(p.prettify()); + #print(p.prettify()); # find all p elements (which contain the current scores) p = soup.find_all("p") @@ -63,34 +61,34 @@ def get_unit_scores(): # 4) reduce value of count by 1 x_text = x.get_text() if "M" in x_text and "spell" in x_text: - # logger.debug("Changing text to Thorr") + # print("Changing text to Thorr") x_text = "Muspell" - # if "Black" in x_text and "Knight" in x_text: - # logger.debug("Changing text to BlackKnight") - # x_text = "BlackKnight" + if "Black" in x_text and "Knight" in x_text: + print("Changing text to BlackKnight") + x_text = "BlackKnight" if not (vg_test): - # logger.debug("VG is NOW!!!") + # print("VG is NOW!!!") y_text = y.get_text() else: - # logger.debug("VG is NOT now!!!") + # print("VG is NOT now!!!") y_text = format (random.randint(0, 10000), ',d') # Iterate through keys to update their values for key in unit_appear: # Check for Male Corrin, then Female Corrin # if (x_text == 'Corrin') and (not unit_dict['MCorrin']): - # logger.debug("Key: " + key + "| Value:" + y_text ) + # print("Key: " + key + "| Value:" + y_text ) # unit_dict['MCorrin'] = y_text # count -= 1 # break # if (x_text == 'Corrin') and (not unit_dict['FCorrin']): - # # logger.debug("Key: " + key + "| Value:" + y_text ) + # # print("Key: " + key + "| Value:" + y_text ) # unit_dict['FCorrin'] = y_text # count -= 1 # break if (x_text == key): unit_appear[key] = unit_appear[key] + 1 if (not unit_scores[key]): - # logger.debug("Key: " + key + "| Value:" + y_text ) + # print("Key: " + key + "| Value:" + y_text ) unit_scores[key] = y_text unit_count -= 1 break @@ -110,13 +108,11 @@ def get_unit_scores(): # custom sort dictionary values into a list keyorder = [vg_unit_1, vg_unit_2, vg_unit_3, vg_unit_4, vg_unit_5, vg_unit_6, vg_unit_7, vg_unit_8] unit_scores_sorted = sorted(unit_scores.items(), key=lambda i:keyorder.index(i[0])) - # logger.debug("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~") - # logger.info(unit_scores) + # print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~") + # print(unit_scores) return unit_scores_sorted def check_vg(unit_scores): - # Set Up Logger - # logger = set_up_logger("gauntlet_template") # Get Current Round Time Variables time_var_current_round = get_time_var_current_round() @@ -132,7 +128,7 @@ def check_vg(unit_scores): time_elapsed = time_now - round_start current_hour = divmod(time_elapsed.total_seconds(), 60*60)[0] hours_remain = 45 - current_hour - # logger.info("hours_remain: " + str(hours_remain)) + # print("hours_remain: " + str(hours_remain)) multiplier = (current_hour * 0.2) + 3.2 # pairwise compare units in battle to detect disadvantages @@ -150,9 +146,9 @@ def check_vg(unit_scores): # variables for checking if multiplier is up for either team disadvantage_a = float(truncate(float(a_score) / float(b_score),4)) disadvantage_b = float(truncate(float(b_score) / float(a_score),4)) - # logger.debug(disadvantage_a) - # logger.debug(disadvantage_b) - # logger.info(f"disadvantage_a: {disadvantage_a} | disadvantage_b: {disadvantage_b}") + # print(disadvantage_a) + # print(disadvantage_b) + # print(f"disadvantage_a: {disadvantage_a} | disadvantage_b: {disadvantage_b}") # Create Dictionary Per Pairwise Comparison, then add to list losing_unit = '' @@ -181,7 +177,7 @@ def check_vg(unit_scores): # vg_scores['Message'] = message # End of Log - # logger.debug("End of successful check") + # print("End of successful check") # return time elapsed return (vg_scores) @@ -194,12 +190,11 @@ def one_hour_string(hours_remain): return "Less than **one** hour remains" def tweet_multiplier(name, multiplier, hours_remain, vg_hashtag, round_name): - # logger = set_up_logger("gauntlet_template") - # logger.debug("Starting tweet_multiplier()") + # print("Starting tweet_multiplier()") unit_random_quote = get_unit_quote_random(name) hour_or_hours = one_hour_string(hours_remain) message = ' is losing with a **%.1fx** multiplier up!\n"%s"\n(%s in %s\'s %s)' % (multiplier, unit_random_quote, hour_or_hours, vg_hashtag, round_name) - # logger.info(message) + # print(message) return message def pairwise_list(iterable): @@ -254,7 +249,6 @@ def get_unit_image_url(unit_name): ## Get Time Variables from config def get_time_var(): - # logger = set_up_logger("gauntlet_template") dic = {} dic['time_now'] = datetime.now() dic['round_1_start'] = datetime.strptime(round_1_start_raw, '%b %d %Y %I:%M%p') @@ -267,7 +261,6 @@ def get_time_var(): ## Get Time Variables for Current Round def get_time_var_current_round(): - # logger = set_up_logger("gauntlet_template") time_var = get_time_var() time_now = time_var['time_now'] round_1_start = time_var['round_1_start'] @@ -282,32 +275,32 @@ def get_time_var_current_round(): if not (vg_test): # round 1 variables if (round_1_start < time_now < round_1_end): - # logger.debug("Currently Round 1") + # print("Currently Round 1") round_start = round_1_start round_name = 'Round 1' unit_count = 8 unit_freq = 1 # round 2 variables elif (round_2_start < time_now < round_2_end): - # logger.debug("Currently Round 2") + # print("Currently Round 2") round_start = round_2_start round_name = 'Round 2' unit_count = 12 unit_freq = 2 # round 3 variables elif (round_3_start < time_now < round_3_end): - # logger.debug("Currently Round 3") + # print("Currently Round 3") round_start = round_3_start round_name = 'Final Round' unit_count = 14 unit_freq = 3 # else in between rounds else: - # logger.debug("Current time in between rounds. Ending execution.") + # print("Current time in between rounds. Ending execution.") return (-1) else: - # logger.debug("~~~~~Testing VG~~~~~") - # logger.debug("Currently Round 3") + # print("~~~~~Testing VG~~~~~") + # print("Currently Round 3") round_start = round_3_start round_name = 'Round 3' unit_count = 14 @@ -324,23 +317,4 @@ def get_time_var_current_round(): dic['unit_count'] = unit_count dic['unit_dict'] = unit_dict dic['unit_freq'] = unit_freq - return dic - -# Set up logger -# def set_up_logger(module_name): -# # Gets or creates a logger -# # logger = logging.getLogger(module_name) - -# # set log level -# # logger.setLevel(logging.DEBUG) -# # logger.setLevel(logging.INFO) - -# # define file handler and set formatter -# file_name = 'logs/' + module_name + '.log' -# file_handler = logging.FileHandler(filename=file_name, encoding='utf-8', mode='w') -# formatter = logging.Formatter('%(asctime)s : %(levelname)s : %(name)s : %(message)s') -# file_handler.setFormatter(formatter) - -# # add file handler to logger -# # logger.addHandler(file_handler) -# return logger + return dic \ No newline at end of file diff --git a/bots/genny/.gitignore b/bots/genny/.gitignore new file mode 100644 index 0000000..f554038 --- /dev/null +++ b/bots/genny/.gitignore @@ -0,0 +1,38 @@ +### --- Python +# virtualenv +*venv* +bin/ +include/ +lib/ +local/ +.DS_Store +secrets* +*.pyc +*.log +nohup.out +__pycache__ +.pytest_cache +.cache +job_manager.db +### --- Golang +# If you prefer the allow list template instead of the deny list, see community template: +# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore +# +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +# Go workspace file +config.json \ No newline at end of file diff --git a/discord/genny/Dockerfile b/bots/genny/Dockerfile similarity index 100% rename from discord/genny/Dockerfile rename to bots/genny/Dockerfile diff --git a/discord/genny/config.py b/bots/genny/config.py similarity index 100% rename from discord/genny/config.py rename to bots/genny/config.py diff --git a/discord/genny/discordclient.py b/bots/genny/discordclient.py similarity index 100% rename from discord/genny/discordclient.py rename to bots/genny/discordclient.py diff --git a/bots/genny/docker-compose.yml b/bots/genny/docker-compose.yml new file mode 100644 index 0000000..1883b25 --- /dev/null +++ b/bots/genny/docker-compose.yml @@ -0,0 +1,15 @@ +version: "3.8" +services: + genny: + build: . + container_name: genny + # image: atemosta/feh-gauntlet-bot:genny-latest + command: python genny.py + restart: unless-stopped + networks: + - feh-vg-bot + volumes: + - ../../assets:/app/assets +networks: + feh-vg-bot: + external: true \ No newline at end of file diff --git a/discord/genny/genny.py b/bots/genny/genny.py similarity index 100% rename from discord/genny/genny.py rename to bots/genny/genny.py diff --git a/discord/genny/requirements.txt b/bots/genny/requirements.txt similarity index 100% rename from discord/genny/requirements.txt rename to bots/genny/requirements.txt diff --git a/bots/golembane/.gitignore b/bots/golembane/.gitignore new file mode 100644 index 0000000..e12c5b9 --- /dev/null +++ b/bots/golembane/.gitignore @@ -0,0 +1,24 @@ +# If you prefer the allow list template instead of the deny list, see community template: +# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore +# +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +# Go workspace file +config.json + +# Docker +.env \ No newline at end of file diff --git a/discord/robin/Dockerfile b/bots/golembane/Dockerfile similarity index 100% rename from discord/robin/Dockerfile rename to bots/golembane/Dockerfile diff --git a/bots/golembane/README.md b/bots/golembane/README.md new file mode 100644 index 0000000..cb3f987 --- /dev/null +++ b/bots/golembane/README.md @@ -0,0 +1,14 @@ +# Golembane +Golang API for FEH-VG-Bots based on [this tutorial ](https://dev.to/aurelievache/learning-go-by-examples-part-2-create-an-http-rest-api-server-in-go-1cdm) + +## Requirements +* Install [Taskfile](https://taskfile.dev/installation/) +* Install [Go-Swagger](https://github.com/go-swagger/go-swagger/blob/master/docs/install.md) + +## Commands +* `go run internal/main.go` -> Starts API +* `go build -o bin/go-rest-api internal/main.go` -> Generates an executable binary with our HTTP server +* `swagger version` +* `task swagger.validate` +* `task swagger.doc` +* `task swagger.gen` \ No newline at end of file diff --git a/bots/golembane/Taskfile.yml b/bots/golembane/Taskfile.yml new file mode 100644 index 0000000..daa60dc --- /dev/null +++ b/bots/golembane/Taskfile.yml @@ -0,0 +1,34 @@ +version: "3" + +tasks: + build: + desc: Build the app + cmds: + # Default Build + - GOFLAGS=-mod=mod go build -o bin/go-rest-api internal/main.go + # Linux 32 bits + # - GOOS=linux GOARCH=386 go build -o bin/go-rest-api-linux-386 internal/main.go + # Linux 64 bits + # - GOOS=linux GOARCH=amd64 go build -o bin/go-rest-api-linux-64 internal/main.go + # MacOS 64 bits for M1 chip + # - GOOS=darwin GOARCH=arm64 go build -o bin/go-rest-api-darwin-arm64 internal/main.go + + run: + desc: Run the app + cmds: + - GOFLAGS=-mod=mod go run internal/main.go + + swagger.gen: + desc: Generate Go code + cmds: + - GOFLAGS=-mod=mod go generate github.com/scraly/learning-go-by-examples/go-rest-api/internal github.com/scraly/learning-go-by-examples/go-rest-api/pkg/swagger + + swagger.validate: + desc: Validate swagger + cmds: + - swagger validate pkg/swagger/swagger.yml + + swagger.doc: + desc: Doc for swagger + cmds: + - docker run -i yousan/swagger-yaml-to-html < pkg/swagger/swagger.yml > doc/index.html \ No newline at end of file diff --git a/bots/golembane/docker-compose.yml b/bots/golembane/docker-compose.yml new file mode 100644 index 0000000..842029c --- /dev/null +++ b/bots/golembane/docker-compose.yml @@ -0,0 +1,16 @@ +version: "3.8" +services: + golembane: + build: ./ + command: go run main.go + container_name: golembane + networks: + - feh-vg-bot + ports: + - '4545:4545' + restart: unless-stopped + # volumes: + # - ../../assets:/app/assets +networks: + feh-vg-bot: + external: true \ No newline at end of file diff --git a/bots/golembane/go.mod b/bots/golembane/go.mod new file mode 100644 index 0000000..f71fd98 --- /dev/null +++ b/bots/golembane/go.mod @@ -0,0 +1,19 @@ +module github.com/atemosta/feh-gauntlet-bot/bots/golembane + +go 1.19 + +require ( + github.com/golang/snappy v0.0.1 // indirect + github.com/gorilla/mux v1.8.0 // indirect + github.com/klauspost/compress v1.13.6 // indirect + github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect + github.com/pkg/errors v0.9.1 // indirect + github.com/xdg-go/pbkdf2 v1.0.0 // indirect + github.com/xdg-go/scram v1.1.1 // indirect + github.com/xdg-go/stringprep v1.0.3 // indirect + github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect + go.mongodb.org/mongo-driver v1.11.1 // indirect + golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // indirect + golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect + golang.org/x/text v0.3.7 // indirect +) diff --git a/bots/golembane/go.sum b/bots/golembane/go.sum new file mode 100644 index 0000000..7c0c5f8 --- /dev/null +++ b/bots/golembane/go.sum @@ -0,0 +1,48 @@ +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4= +github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= +github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= +github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc= +github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe h1:iruDEfMl2E6fbMZ9s0scYfZQ84/6SPL6zC8ACM2oIL0= +github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= +github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c= +github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= +github.com/xdg-go/scram v1.1.1 h1:VOMT+81stJgXW3CpHyqHN3AXDYIMsx56mEFrB37Mb/E= +github.com/xdg-go/scram v1.1.1/go.mod h1:RaEWvsqvNKKvBPvcKeFjrG2cJqOkHTiyTpzz23ni57g= +github.com/xdg-go/stringprep v1.0.3 h1:kdwGpVNwPFtjs98xCGkHjQtGKh86rDcRZN17QEMCOIs= +github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8= +github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA= +github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA= +go.mongodb.org/mongo-driver v1.11.1 h1:QP0znIRTuL0jf1oBQoAoM0C6ZJfBK4kx0Uumtv1A7w8= +go.mongodb.org/mongo-driver v1.11.1/go.mod h1:s7p5vEtfbeR1gYi6pnj3c3/urpbLv2T5Sfd6Rp2HBB8= +golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d h1:sK3txAijHtOK88l68nt020reeT1ZdKLIYetKl95FzVY= +golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/bots/golembane/main.go b/bots/golembane/main.go new file mode 100644 index 0000000..16fa8a0 --- /dev/null +++ b/bots/golembane/main.go @@ -0,0 +1,244 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + "io/ioutil" + "log" + "net/http" + "time" + "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/mongo/options" + "github.com/gorilla/mux" +) + +type Article struct { + Id string `json:"Id"` + Title string `json:"Title"` + Desc string `json:"desc"` + Content string `json:"content"` +} + +type Command struct { + Name string + Value string +} + +type CommandDB struct { + ID primitive.ObjectID `bson:"_id"` + Name string + Value string +} + +// let's declare a global Articles array +// that we can then populate in our main function +// to simulate a database +var Articles []Article + +func homePage(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf(w, "Welcome to the HomePage!") + fmt.Println("Endpoint Hit: homePage") +} + +func returnAllArticles(w http.ResponseWriter, r *http.Request) { + fmt.Println("Endpoint Hit: returnAllArticles") + json.NewEncoder(w).Encode(Articles) +} + +func createNewArticle(w http.ResponseWriter, r *http.Request) { + fmt.Println("Endpoint Hit: createNewArticle") + // get the body of our POST request + // unmarshal this into a new Article struct + // append this to our Articles array. + reqBody, _ := ioutil.ReadAll(r.Body) + var article Article + json.Unmarshal(reqBody, &article) + // update our global Articles array to include + // our new Article + Articles = append(Articles, article) + json.NewEncoder(w).Encode(article) +} + +func createNewCommand(w http.ResponseWriter, r *http.Request) { + fmt.Println("Endpoint Hit: createNewCommand") + // get the body of our POST request + // unmarshal this into a new Article struct + // append this to our Articles array. + reqBody, _ := ioutil.ReadAll(r.Body) + var command Command + json.Unmarshal(reqBody, &command) + + // Add command to our database + // mongodb://[username:password@]host1[:port1][,...hostN[:portN]][/[defaultauthdb][?options]] + client, err := mongo.NewClient(options.Client().ApplyURI("mongodb://root:pass12345@localhost")) + if err != nil { + log.Fatal(err) + } + ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) + err = client.Connect(ctx) + if err != nil { + log.Fatal(err) + } + defer client.Disconnect(ctx) + + /* List Get Robin Bot Collection */ + fehDatabase := client.Database("feh") + robinCollection := fehDatabase.Collection("robin") + robinResult, err := robinCollection.InsertOne(ctx, command) + if err != nil { + log.Fatal(err) + } + + // Print Return Statement + fmt.Println(command) + fmt.Println(robinResult) + json.NewEncoder(w).Encode(command) +} + + +func deleteArticle(w http.ResponseWriter, r *http.Request) { + fmt.Println("Endpoint Hit: deleteArticle") + // once again, we will need to parse the path parameters + vars := mux.Vars(r) + // we will need to extract the `id` of the article we + // wish to delete + id := vars["id"] + + // we then need to loop through all our articles + for index, article := range Articles { + // if our id path parameter matches one of our + // articles + if article.Id == id { + // updates our Articles array to remove the + // article + Articles = append(Articles[:index], Articles[index+1:]...) + } + } + fmt.Fprintf(w, "Successfully delete Article Id: " + id) +} + +func getCommandValue(w http.ResponseWriter, r *http.Request){ + fmt.Println("Endpoint Hit: getCommandValue") + vars := mux.Vars(r) + name := vars["name"] + + // Connect to our DB + // mongodb://[username:password@]host1[:port1][,...hostN[:portN]][/[defaultauthdb][?options]] + client, err := mongo.NewClient(options.Client().ApplyURI("mongodb://root:pass12345@localhost")) + if err != nil { + log.Fatal(err) + } + ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) + err = client.Connect(ctx) + if err != nil { + log.Fatal(err) + } + defer client.Disconnect(ctx) + + /* Get Document by Filter */ + collection := client.Database("feh").Collection("robin") + filterFind := bson.D{{"name", name}} + var result Command + err = collection.FindOne(context.TODO(), filterFind).Decode(&result) + if err != nil { + panic(err) + } + fmt.Println("Command Name: " + result.Name) + fmt.Println("Command Value: " + result.Value) + json.NewEncoder(w).Encode(result) + fmt.Println("Successfully returned command value!") +} + +func returnSingleArticle(w http.ResponseWriter, r *http.Request){ + fmt.Println("Endpoint Hit: returnSingleArticle") + vars := mux.Vars(r) + key := vars["id"] + // Loop over all of our Articles + // if the article.Id equals the key we pass in + // return the article encoded as JSON + for _, article := range Articles { + if article.Id == key { + json.NewEncoder(w).Encode(article) + } + } +} + +func updateExistingCommand(w http.ResponseWriter, r *http.Request){ + fmt.Println("Endpoint Hit: updateExistingCommand") + // get the body of our POST request + // unmarshal this into a new Article struct + // append this to our Articles array. + reqBody, _ := ioutil.ReadAll(r.Body) + var command Command + json.Unmarshal(reqBody, &command) + cName := command.Name + cValue := command.Value + + // Add command to our database + // mongodb://[username:password@]host1[:port1][,...hostN[:portN]][/[defaultauthdb][?options]] + client, err := mongo.NewClient(options.Client().ApplyURI("mongodb://root:pass12345@localhost")) + if err != nil { + log.Fatal(err) + } + ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) + err = client.Connect(ctx) + if err != nil { + log.Fatal(err) + } + defer client.Disconnect(ctx) + + /* Get Document by Filter */ + collection := client.Database("feh").Collection("robin") + filterFind := bson.D{{"name", cName}} + var result CommandDB + err = collection.FindOne(context.TODO(), filterFind).Decode(&result) + if err != nil { + panic(err) + } + fmt.Println(result.ID.Hex()) + fmt.Println(result.Name) + fmt.Println(result.Value) + + /* Update Document by Id */ + id, _ := primitive.ObjectIDFromHex(result.ID.Hex()) + filterUpdate := bson.D{{"_id", id}} + valueUpdate := bson.D{{"$set", bson.D{{"value", cValue}}}} + resultUpdate, err := collection.UpdateOne(context.TODO(), filterUpdate, valueUpdate) + if err != nil { + panic(err) + } + fmt.Println(resultUpdate) + + // Return Statement + returnStatement := "Successfully update command: ||" + cName + "|| with value: ||" + cValue + "||" + fmt.Fprintf(w, returnStatement) + fmt.Println(returnStatement) +} + +// REST Endpoints +func handleRequests() { + // Creates a new instance of a mux router + myRouter := mux.NewRouter().StrictSlash(true) + myRouter.HandleFunc("/", homePage) + myRouter.HandleFunc("/all", returnAllArticles) + myRouter.HandleFunc("/article", createNewArticle).Methods("POST") + myRouter.HandleFunc("/article/{id}", deleteArticle).Methods("DELETE") + myRouter.HandleFunc("/article/{id}", returnSingleArticle) + myRouter.HandleFunc("/command", createNewCommand).Methods("POST") + myRouter.HandleFunc("/command", updateExistingCommand).Methods("PATCH") + myRouter.HandleFunc("/command/{name}", getCommandValue).Methods("GET") + log.Fatal(http.ListenAndServe(":4545", myRouter)) +} + +// Main Function +func main() { + fmt.Println("Starting Server...") + Articles = []Article{ + Article{Id: "1", Title: "Hello", Desc: "Article Description", Content: "Article Content"}, + Article{Id: "2", Title: "Hello 2", Desc: "Article Description", Content: "Article Content"}, + } + handleRequests() +} diff --git a/bots/golembane/test.go b/bots/golembane/test.go new file mode 100644 index 0000000..7da92a5 --- /dev/null +++ b/bots/golembane/test.go @@ -0,0 +1,40 @@ +func updateExistingCommand(w http.ResponseWriter, r *http.Request) { + fmt.Println("Endpoint Hit: updateExistingCommand") + // get the body of our POST request + // unmarshal this into a new Article struct + // append this to our Articles array. + reqBody, _ := ioutil.ReadAll(r.Body) + var command Command + json.Unmarshal(reqBody, &command) + + // Add command to our database + // mongodb://[username:password@]host1[:port1][,...hostN[:portN]][/[defaultauthdb][?options]] + client, err := mongo.NewClient(options.Client().ApplyURI("mongodb://root:pass12345@localhost")) + if err != nil { + log.Fatal(err) + } + ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) + err = client.Connect(ctx) + if err != nil { + log.Fatal(err) + } + defer client.Disconnect(ctx) + + /* Get Document by Filter */ + // collection := client.Database("feh").Collection("robin") + // filter := bson.D{{"name", "calendar"}} + // var result Command + // err = collection.FindOne(context.TODO(), filter).Decode(&result) + // fmt.Println(result) + // fmt.Println(result.name) + // fmt.Println(result.value) + + // robinResult, err := robinCollection.InsertOne(ctx, command) + // if err != nil { + // log.Fatal(err) + // } + + // Print Return Statement + // son.NewEncoder(w).Encode(command) + fmt.Println("Endpoint Hit: updateExistingCommand") +} diff --git a/bots/mongodb/.env b/bots/mongodb/.env new file mode 100644 index 0000000..a669028 --- /dev/null +++ b/bots/mongodb/.env @@ -0,0 +1,4 @@ +MONGO_INITDB_ROOT_USERNAME=root +MONGO_INITDB_ROOT_PASSWORD=pass12345 +ME_CONFIG_BASICAUTH_USERNAME=dioxide30 +ME_CONFIG_BASICAUTH_PASSWORD=sLukFQaoo6EpmE0DaQkO06X1kgtXym2Uz7ZakQF7WOLFBnTx3rN2UtHYHPG7lqKZ \ No newline at end of file diff --git a/bots/mongodb/.env-example b/bots/mongodb/.env-example new file mode 100644 index 0000000..0d1a769 --- /dev/null +++ b/bots/mongodb/.env-example @@ -0,0 +1,9 @@ +MONGO_INITDB_ROOT_USERNAME=root +MONGO_INITDB_ROOT_PASSWORD=pass12345 +MONGO_INITDB_DATABASE=feh +ME_CONFIG_MONGODB_SERVER=mongo-db-feh +ME_CONFIG_MONGODB_ENABLE_ADMIN=true +ME_CONFIG_MONGODB_ADMINUSERNAME=root +ME_CONFIG_MONGODB_ADMINPASSWORD=pass12345 +ME_CONFIG_BASICAUTH_USERNAME=admin +ME_CONFIG_BASICAUTH_PASSWORD=admin123 \ No newline at end of file diff --git a/bots/mongodb/README.md b/bots/mongodb/README.md new file mode 100644 index 0000000..8af2620 --- /dev/null +++ b/bots/mongodb/README.md @@ -0,0 +1,2 @@ +# MongoDB +NoSQL Databases deployed via Docker \ No newline at end of file diff --git a/bots/mongodb/deploy-db.sh b/bots/mongodb/deploy-db.sh new file mode 100755 index 0000000..f08f837 --- /dev/null +++ b/bots/mongodb/deploy-db.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +# Copy Secret Credentials to Mounted Volume +# echo "Attempting to copy secret credentials..." +# cp secrets.py assets/ +# echo "Successfully copied secret credentials!" + +# Run Latest Docker Images +echo "Attempting to Deploy MongoDB Docker images..." +docker compose down +docker compose up -d +echo "Successfully Deployed MongoDB Docker images!" \ No newline at end of file diff --git a/bots/mongodb/docker-compose.yml b/bots/mongodb/docker-compose.yml new file mode 100644 index 0000000..4f529be --- /dev/null +++ b/bots/mongodb/docker-compose.yml @@ -0,0 +1,19 @@ +version: "3.8" +services: + mongo-db-feh: + container_name: mongo-db-feh + image: mongo + environment: + - MONGO_INITDB_ROOT_USERNAME=${MONGO_INITDB_ROOT_USERNAME} + - MONGO_INITDB_ROOT_PASSWORD=${MONGO_INITDB_ROOT_PASSWORD} + - MONGO_INITDB_DATABASE=feh + networks: + - feh-vg-bot + ports: + - '27017:27017' + restart: unless-stopped + volumes: + - mongodb-data-feh:/data/db +networks: + feh-vg-bot: + external: true \ No newline at end of file diff --git a/bots/rebecca/.gitignore b/bots/rebecca/.gitignore new file mode 100644 index 0000000..f554038 --- /dev/null +++ b/bots/rebecca/.gitignore @@ -0,0 +1,38 @@ +### --- Python +# virtualenv +*venv* +bin/ +include/ +lib/ +local/ +.DS_Store +secrets* +*.pyc +*.log +nohup.out +__pycache__ +.pytest_cache +.cache +job_manager.db +### --- Golang +# If you prefer the allow list template instead of the deny list, see community template: +# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore +# +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +# Go workspace file +config.json \ No newline at end of file diff --git a/discord/rebecca/Dockerfile b/bots/rebecca/Dockerfile similarity index 100% rename from discord/rebecca/Dockerfile rename to bots/rebecca/Dockerfile diff --git a/discord/rebecca/Pipfile b/bots/rebecca/Pipfile similarity index 100% rename from discord/rebecca/Pipfile rename to bots/rebecca/Pipfile diff --git a/discord/rebecca/Pipfile.lock b/bots/rebecca/Pipfile.lock similarity index 100% rename from discord/rebecca/Pipfile.lock rename to bots/rebecca/Pipfile.lock diff --git a/discord/rebecca/config.py b/bots/rebecca/config.py similarity index 100% rename from discord/rebecca/config.py rename to bots/rebecca/config.py diff --git a/discord/rebecca/discordclient.py b/bots/rebecca/discordclient.py similarity index 100% rename from discord/rebecca/discordclient.py rename to bots/rebecca/discordclient.py diff --git a/bots/rebecca/docker-compose.yml b/bots/rebecca/docker-compose.yml new file mode 100644 index 0000000..234cd6b --- /dev/null +++ b/bots/rebecca/docker-compose.yml @@ -0,0 +1,15 @@ +version: "3.8" +services: + rebecca: + build: . + container_name: rebecca + # image: atemosta/feh-gauntlet-bot:rebecca-latest + command: python rebecca.py + restart: unless-stopped + networks: + - feh-vg-bot + volumes: + - ../../assets-discord:/app/assets +networks: + feh-vg-bot: + external: true \ No newline at end of file diff --git a/discord/rebecca/rebecca.py b/bots/rebecca/rebecca.py similarity index 98% rename from discord/rebecca/rebecca.py rename to bots/rebecca/rebecca.py index 94f3cf3..a95e5ff 100644 --- a/discord/rebecca/rebecca.py +++ b/bots/rebecca/rebecca.py @@ -69,7 +69,11 @@ async def on_message(self, message): # if check_unit_validity(unit_name): if (rest_get(f'unit/check/{unit_name}'))['is_valid']: # Check if role exists, and add/remove if approriate - unit_name_index = unit_name.title() + # unit_name_index = unit_name.title() + unit_name_index = unit_name + # Rename index if you are special + # if unit_name == "BlackKnight": + # unit_name_index = "BlackKnight" # unit_name_index = unit_name role = discord.utils.get(member.guild.roles, name=f"Team {unit_name_index}") if (role): diff --git a/bots/rebecca/requirements.txt b/bots/rebecca/requirements.txt new file mode 100644 index 0000000..6e0f9ba --- /dev/null +++ b/bots/rebecca/requirements.txt @@ -0,0 +1,22 @@ +aiohttp==3.7.4.post0 +APScheduler==3.7.0 +async-timeout==3.0.1 +attrs==21.2.0 +certifi==2022.12.7 +chardet==4.0.0 +charset-normalizer==2.0.6 +discord==1.7.3 +discord.py==1.7.3 +idna==3.2 +multidict==5.1.0 +oauthlib==3.2.1 +PySocks==1.7.1 +pytz==2021.1 +requests==2.26.0 +requests-oauthlib==1.3.0 +six==1.16.0 +tweepy==3.10.0 +typing-extensions==3.10.0.2 +tzlocal==2.1 +urllib3==1.26.6 +yarl==1.6.3 \ No newline at end of file diff --git a/bots/robin/.gitignore b/bots/robin/.gitignore new file mode 100644 index 0000000..0cffcb3 --- /dev/null +++ b/bots/robin/.gitignore @@ -0,0 +1 @@ +config.json \ No newline at end of file diff --git a/bots/robin/Dockerfile b/bots/robin/Dockerfile new file mode 100644 index 0000000..fc7824c --- /dev/null +++ b/bots/robin/Dockerfile @@ -0,0 +1,14 @@ +# Select Docker image +FROM golang:1.19.3-alpine3.16 + +# Create app directory +WORKDIR /app + +# Copy Source Code into /app +ADD . /app/ + +# Install app dependencies +RUN go build -o main . + +# Run Bot +CMD ["./main"] diff --git a/discord/robin/README.md b/bots/robin/README.md similarity index 100% rename from discord/robin/README.md rename to bots/robin/README.md diff --git a/discord/robin/bot/bot.go b/bots/robin/bot/bot.go similarity index 100% rename from discord/robin/bot/bot.go rename to bots/robin/bot/bot.go diff --git a/bots/robin/config-example.json b/bots/robin/config-example.json new file mode 100644 index 0000000..3b004d4 --- /dev/null +++ b/bots/robin/config-example.json @@ -0,0 +1,4 @@ +{ + "Token" : "<>", + "BotPrefix" : "++" +} \ No newline at end of file diff --git a/discord/robin/config.json.example b/bots/robin/config.json.example similarity index 100% rename from discord/robin/config.json.example rename to bots/robin/config.json.example diff --git a/discord/robin/config/config.go b/bots/robin/config/config.go similarity index 100% rename from discord/robin/config/config.go rename to bots/robin/config/config.go diff --git a/bots/robin/docker-compose.yml b/bots/robin/docker-compose.yml new file mode 100644 index 0000000..1919d69 --- /dev/null +++ b/bots/robin/docker-compose.yml @@ -0,0 +1,14 @@ +version: "3.8" +services: + robin: + build: ./ + container_name: robin + command: go run main.go + restart: unless-stopped + networks: + - feh-vg-bot + # volumes: + # - ../../assets:/app/assets +networks: + feh-vg-bot: + external: true \ No newline at end of file diff --git a/discord/robin/go.mod b/bots/robin/go.mod similarity index 100% rename from discord/robin/go.mod rename to bots/robin/go.mod diff --git a/discord/robin/go.sum b/bots/robin/go.sum similarity index 100% rename from discord/robin/go.sum rename to bots/robin/go.sum diff --git a/discord/robin/main b/bots/robin/main similarity index 100% rename from discord/robin/main rename to bots/robin/main diff --git a/discord/robin/main.go b/bots/robin/main.go similarity index 100% rename from discord/robin/main.go rename to bots/robin/main.go diff --git a/discord/unit_test.py b/bots/unit_test.py similarity index 100% rename from discord/unit_test.py rename to bots/unit_test.py diff --git a/discord/robin/docker-compose.yml b/discord/robin/docker-compose.yml deleted file mode 100644 index 74bdd7b..0000000 --- a/discord/robin/docker-compose.yml +++ /dev/null @@ -1,7 +0,0 @@ -version: "3.8" -services: - robin: - build: ./ - container_name: robin - command: go run main.go - restart: always \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 917336c..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,45 +0,0 @@ -version: "3.8" -services: - convoy: - build: convoy - container_name: convoy - # image: atemosta/feh-gauntlet-bot:convoy-latest - command: uvicorn api:app --host 0.0.0.0 --port 5057 --reload - restart: always - networks: - - feh-compose-network - ports: - - 5057:5057 - volumes: - - ./assets:/app/assets - genny: - build: discord/genny - container_name: genny - # image: atemosta/feh-gauntlet-bot:genny-latest - command: python genny.py - restart: always - depends_on: - - convoy - networks: - - feh-compose-network - ports: - - 4545:4545 - volumes: - - ./assets:/app/assets - rebecca: - build: discord/rebecca - container_name: rebecca - # image: atemosta/feh-gauntlet-bot:rebecca-latest - command: python rebecca.py - restart: always - depends_on: - - convoy - networks: - - feh-compose-network - ports: - - 4546:4546 - volumes: - - ./assets:/app/assets -networks: - feh-compose-network: - driver: bridge \ No newline at end of file