From 86927f595c4de32b04ca44cae7db702f8ff4eb69 Mon Sep 17 00:00:00 2001 From: silverwizard Date: Fri, 18 Jun 2021 22:43:08 -0400 Subject: [PATCH] Added init tracking for playing Shadowrun 5 properly using SqlLite --- __pycache__/shadowdice.cpython-38.pyc | Bin 12420 -> 15953 bytes aliases.csv | 1 + help.html | 7 +- metadata.ini | 7 +- privileges.csv | 4 +- shadowdice.py | 136 +++++++++++++++++++++++--- 6 files changed, 140 insertions(+), 15 deletions(-) diff --git a/__pycache__/shadowdice.cpython-38.pyc b/__pycache__/shadowdice.cpython-38.pyc index 2b9659ba53dc9db13c888fcb4a87930a82456cf4..7aec962cafe028fc4e422aead58ff15d3a2901f6 100644 GIT binary patch delta 5214 zcma)ATWlOx8J;uuy?T9#FG-qAoF>jDu2YhzC6~InZPPTx3AWS3F2z~z8OOU>&)8?q z=CaIo3keiZ3yB7V5Di-M)=Ef7Mu^Ao08d=X>qtBx9-u;k2Of~Z1N{G)^=;X-@oK&~ zbLN~gbN>JP|L-5)%m2|&Urwds68v4A`rWl(oO_VoPW%T43jI`~W;rvRIVaH=jo*`K z+$MLG>COi~4#)?=A>v-919a;>X}W`Mqub$}q0i7AaPFi#sRidQx{D6Nx%*v7m8N?p zr0niczf`VVFFFN+4{ZLaaMs~a;P4&=zb8|5-r4A)+A^uhzTD_umTHQxG z#u&a#mV{c_%~LNVBh{cP_gr{v6rCa;p|g)qo*B=bn#@^~r%u0~v#{5*_R(U&hBhCz zW?iS^MNRJVd^u`5`32kZI4e5Wv%z=dL&OSxB`<%@@RrI&ZXXVfg6lYTfromb!aSFS zhJD*ERJaWt?!rQmhgzZRdUlXku5MF9)w9cU4E+>}_nM)zp^C2({917ayP!Xf<{Jc% zNSq`|Kk0#AoS5P;gA3|`I$9VleFhG15`aq$LJ8QJ_@p6&ozdP3m4%&2Llt%=4Ncft z0Xys5;3ieUvN5o*_E6z*o+u?tDXOno)EHw)So?A2?D)k?8;$mbSE^?2c9DZgtZLj^ z6jT@)8D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WD&;9&DWg=Z z2VT(N$NHzdhTUJ`s44ZHZSwV=1M)|sl*3etOq=t7SH%!q= zgV%f(%tlFU9bd??lxtv=ODVoXev{hnO_~naP@M|=Mi?2~7FA)-i%92o*ziO|oyZU~ zPFQ7*y*|K3eU?>G8&e=W3?MW^707Fgs!%Mt393P}P;<14>at?ytd6xCIe^OT-*Q{1 zegG7oR=^*-cfa)L{2)x?hY+|CAC$-QrJ18BzKIw@977xj;OS7lh!{s)LR9Bh%tOSI0luUMx2pf=ZCMxku+a=R$j%a z*8!8J{mg=wA9w@CWRBZ5o3^jEpKd;!yok0&dfoN~WEwj8VS=B9hQEV2x7P8WuhGNn z-I&HzYv6D{geU5w_Q%`rD}%8Q>Nq=&97D-|fwG0l%=VmHHov{t9^F|A|DO+ z)2vLDcPz%wU;Jhc;BogOt{`fNDZ~xLG-3wfAY4F{u2$Rh((4{M@SXb--04qdXh1hG$nW R@k3O=JN|Dm;C>s4zX5I~rDgyC diff --git a/aliases.csv b/aliases.csv index 18daf09..e0041c8 100644 --- a/aliases.csv +++ b/aliases.csv @@ -1,2 +1,3 @@ alias,command predge,(preedge) +pass,(initpass) diff --git a/help.html b/help.html index 19f638d..9c71aa9 100644 --- a/help.html +++ b/help.html @@ -1,5 +1,10 @@ All commands can be run by typing it in the chat or privately messaging JJMumbleBot.
-!init: Roll init dice !init 4 11 will roll 4d6+11
+!addinit: Roll init for a user !init 4 11 Malta will add Malta with 4d6+11
+!listinit: List all inits in the init DB
+!rollinit: Rolls the inits for all of the users, and outputs it
+!initpass: Subtracts 10 from all inits, minimum 0
+!interupt: Subtracts an amount from a single user's init, wont work if you try to subtract more init from the character than they have !interupt Malta 7 will subtract 7 init from Malta
+!clearinit: Deletes all of the initiatives
!srun: Roll a bunch of dice, count successes and ones !srun 12 will roll a pool of 12 dice
!preedge: Roll a pool with exploding 6s, counts successes, ones, and explosions !preedge 12 will roll a poll of 12 dice
!assensing: Prints the Shadowrun assensing table
diff --git a/metadata.ini b/metadata.ini index 9c7d0ce..d22c8b1 100644 --- a/metadata.ini +++ b/metadata.ini @@ -4,7 +4,12 @@ PluginName = Shadow Dice PluginDescription = A plugin for rolling dice in Shadowrun 5e. PluginLanguage = EN PluginCommands: [ - "init", + "rollinit", + "addinit", + "listinit", + "initpass", + "clearinit", + "interupt", "srun", "preedge", "assensing", diff --git a/privileges.csv b/privileges.csv index f2deeff..0c6d031 100644 --- a/privileges.csv +++ b/privileges.csv @@ -1,5 +1,7 @@ command,level -init,1 +rollinit,1 +addinit,1 +listinit,1 srun,1 preedge,1 assensing,1 diff --git a/shadowdice.py b/shadowdice.py index 8c9c7ec..a0a7cc3 100644 --- a/shadowdice.py +++ b/shadowdice.py @@ -7,6 +7,7 @@ from JJMumbleBot.settings import global_settings as gs from JJMumbleBot.lib.resources.strings import * import os import random +import sqlite3 class Plugin(PluginBase): @@ -16,6 +17,11 @@ class Plugin(PluginBase): self.plugin_name = os.path.basename(__file__).rsplit('.')[0] self.metadata = PluginUtilityService.process_metadata(f'plugins/extensions/{self.plugin_name}') self.plugin_cmds = loads(self.metadata.get(C_PLUGIN_INFO, P_PLUGIN_CMDS)) + init_db = sqlite3.connect('init.db') + init = init_db.cursor() + init.execute("CREATE TABLE inits (dice int, bonus int, total int, name string)") + init_db.commit() + init_db.close() self.is_running = True log( INFO, @@ -25,6 +31,11 @@ class Plugin(PluginBase): ) def quit(self): + init_db = sqlite3.connect('init.db') + init = init_db.cursor() + init.execute("DROP TABLE inits") + init_db.commit() + init_db.close() self.is_running = False log( INFO, @@ -41,21 +52,122 @@ class Plugin(PluginBase): if not self.is_running: self.__init__() - def cmd_init(self, data): + def cmd_addinit(self,data): all_data = data.message.strip().split() try: number_of_dice = int(all_data[1]) init_bonus = int(all_data[2]) - ret_text = "
Init Roll:
" - result = 0 - for i in range(number_of_dice): - random.seed(int.from_bytes(os.urandom(8), byteorder="big")) - this_die = random.randint(1,6) - result = result + this_die - ret_text += f"{this_die} + " - result = result + init_bonus - ret_text += f" {init_bonus}
{result}" + character_name = str(all_data[3]) + init_db = sqlite3.connect('init.db') + cur = init_db.cursor() + cur.execute("INSERT INTO inits values (?,?,?,?)", (number_of_dice, init_bonus, 0, character_name)) + init_db.commit() + init_db.close() + gs.gui_service.quick_gui("Added init for: " + character_name, text_type='header', box_align='left') + except IndexError: + log(ERROR, CMD_INVALID_CUSTOM_ROLL, + origin=L_COMMAND, error_type=CMD_INVALID_ERR, print_mode=PrintMode.VERBOSE_PRINT.value) + gs.gui_service.quick_gui(CMD_INVALID_CUSTOM_ROLL, + text_type='header', box_align='left') + return + + def cmd_listinit(self,data): + try: + init_db = sqlite3.connect('init.db') + cur = init_db.cursor() + cur.execute("SELECT * from inits ORDER BY total DESC") + ret_text = "" + for row in cur: + ret_text += str(row[3]) + ": " + str(row[2]) + "
" + init_db.close() gs.gui_service.quick_gui(ret_text, text_type='header', box_align='left') + except IndexError: + log(ERROR, CMD_INVALID_CUSTOM_ROLL, + origin=L_COMMAND, error_type=CMD_INVALID_ERR, print_mode=PrintMode.VERBOSE_PRINT.value) + gs.gui_service.quick_gui(CMD_INVALID_CUSTOM_ROLL, + text_type='header', box_align='left') + return + + def cmd_initpass(self, data): + try: + init_db = sqlite3.connect('init.db') + cur = init_db.cursor() + cur.execute("SELECT * from inits ORDER BY total DESC") + init = init_db.cursor() + ret_text = "" + for row in cur: + new_init = int(row[2])-10 + if(new_init <= 0): + new_init = 0 + init.execute("UPDATE inits SET total = :result WHERE name = :name", {"result": new_init, "name": row[3]}) + ret_text += str(row[3]) + ": " + str(new_init) + "
" + init_db.commit() + init_db.close() + gs.gui_service.quick_gui(ret_text, text_type='header', box_align='left') + except IndexError: + log(ERROR, CMD_INVALID_CUSTOM_ROLL, + origin=L_COMMAND, error_type=CMD_INVALID_ERR, print_mode=PrintMode.VERBOSE_PRINT.value) + gs.gui_service.quick_gui(CMD_INVALID_CUSTOM_ROLL, + text_type='header', box_align='left') + return + + def cmd_interupt(self, data): + all_data = data.message.strip().split() + try: + name = str(all_data[1]) + subtract = int(all_data[2]) + init_db = sqlite3.connect('init.db') + cur = init_db.cursor() + cur.execute("SELECT * from inits WHERE name = :name", {"name": name}) + for row in cur: + new_init = int(row[2])-subtract + if(new_init < 0): + gs.gui_service.quick_gui("Cannot take action, not enought init", text_type='header', box_align='left') + else: + cur.execute("UPDATE inits SET total = :result WHERE name = :name", {"result": new_init, "name": name}) + gs.gui_service.quick_gui(name + ": " + str(new_init), text_type='header', box_align='left') + init_db.commit() + init_db.close() + except IndexError: + log(ERROR, CMD_INVALID_CUSTOM_ROLL, + origin=L_COMMAND, error_type=CMD_INVALID_ERR, print_mode=PrintMode.VERBOSE_PRINT.value) + gs.gui_service.quick_gui("Can only subtract init from a name in the list of inits, try !listinit to confirm spellings", + text_type='header', box_align='left') + return + + def cmd_clearinit(self, data): + init_db = sqlite3.connect('init.db') + init = init_db.cursor() + init.execute("DROP TABLE inits") + init_db.commit() + init.execute("CREATE TABLE inits (dice int, bonus int, total int, name string)") + init_db.commit() + init_db.close() + + def cmd_rollinit(self, data): + try: + init_db = sqlite3.connect('init.db') + cur = init_db.cursor() + init = init_db.cursor() + cur.execute("SELECT * from inits") + ret_text = "" + for row in cur.fetchall(): + ret_text += str(row) + number_of_dice = int(row[0]) + init_bonus = int(row[1]) + ret_text = "
Init For " + str(row[3]) + ":
" + result = 0 + for i in range(number_of_dice): + random.seed(int.from_bytes(os.urandom(8), byteorder="big")) + this_die = random.randint(1,6) + result = result + this_die + ret_text += f"{this_die} + " + result = result + init_bonus + init.execute("UPDATE inits SET total = :result WHERE name = :name", {"result": result, "name": row[3]}) + ret_text += f" {init_bonus}
{result}" + gs.gui_service.quick_gui(ret_text, text_type='header', box_align='left') + init_db.commit() + init_db.close() return except IndexError: log(ERROR, CMD_INVALID_CUSTOM_ROLL, @@ -68,7 +180,7 @@ class Plugin(PluginBase): all_data = data.message.strip().split() try: number_of_dice = int(all_data[1]) - ret_text = "
Die Pool:
" + ret_text = "
Die Pool:
" successes = 0 ones = 0 for i in range(number_of_dice): @@ -93,7 +205,7 @@ class Plugin(PluginBase): all_data = data.message.strip().split() try: number_of_dice = int(all_data[1]) - ret_text = "
Die Pool:
" + ret_text = "
Die Pool:
" successes = 0 ones = 0 explosions = 0