From 9aea2cf9dc1e6b184261771ef3af960822032f4c Mon Sep 17 00:00:00 2001 From: Sakimori Date: Sun, 20 Dec 2020 05:28:47 -0500 Subject: [PATCH] added m!roman [int]; returns error string or a number in roman numerals --- roman.py | 59 +++++++++++++++++++++++++++++++++++++++++++++ the-prestige.pyproj | 1 + the_prestige.py | 9 ++++++- 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 roman.py diff --git a/roman.py b/roman.py new file mode 100644 index 0000000..1af75bb --- /dev/null +++ b/roman.py @@ -0,0 +1,59 @@ +from random import * +from math import * + +int_dict = { 1 : "I", 5 : "V", 10 : "X", 50 : "L", 100 : "C", 500 : "D", 1000 : "M", 5000 : "V̄", 10000 : "X̄", 50000 : "L̄", 100000 : "C̄", 500000 : "D̄", 1000000 : "M̄"} +int_list = [1000000,500000,100000,50000,10000,5000,1000,500,100,50,10,5,1] +int_in = 0 +string_out = "" + + +def roman_convert(int_in_string): + global string_out + global int_in + string_out = "" + int_in = int(int_in_string) + if int_in >= 4000000: + return "Please keep it less than 4,000,000, we don't know how to write 2 macrons." + for poss_int in int_list: + if str(poss_int)[0] == "1": + addstring1(poss_int) + addstring9(poss_int) + else: + addstring5(poss_int) + addstring4(poss_int) + return string_out + + +def addstring1(num): + global string_out + global int_in + while int_in >= num: + string_out += int_dict[num] + int_in = int_in - num + +def addstring4(num5): + global string_out + global int_in + if int_in >= num5 * 4 / 5: + string_out += int_dict[int(num5/5)] + int_dict[num5] + int_in = int_in - (num5 * 4 / 5) + +def addstring5(num5): + global string_out + global int_in + if int_in >= num5: + string_out += int_dict[num5] + int_in = int_in - num5 + +def addstring9(num10): + global string_out + global int_in + if num10 == 1: + return + if int_in >= num10 * 9 / 10: + string_out += int_dict[int(num10/10)] + int_dict[num10] + int_in = int_in - num10 * 9 / 10 + + +def randbool(): + return (randint(0,1) == 1) \ No newline at end of file diff --git a/the-prestige.pyproj b/the-prestige.pyproj index 4f1cecf..9f63274 100644 --- a/the-prestige.pyproj +++ b/the-prestige.pyproj @@ -28,6 +28,7 @@ Code + diff --git a/the_prestige.py b/the_prestige.py index 4a91e19..2117dc4 100644 --- a/the_prestige.py +++ b/the_prestige.py @@ -1,4 +1,4 @@ -import discord, json, os +import discord, json, os, roman import database as db import onomancer as ono @@ -49,6 +49,13 @@ async def on_message(msg): except AttributeError: await msg.channel.send(ono.get_stats(msg.author.name)) + elif command.startswith("roman "): + possible_int_string = command.split(" ",1)[1] + try: + await msg.channel.send(roman.roman_convert(possible_int_string)) + except ValueError: + await msg.channel.send(f"\"{possible_int_string}\" isn't an integer in Arabic numerals.") + elif command == "credit": await msg.channel.send("Our avatar was graciously provided to us, with permission, by @HetreaSky on Twitter.")