Added init tracking for playing Shadowrun 5 properly using SqlLite

main
silverwizard 3 years ago
parent 1ae050c3b2
commit 86927f595c
  1. BIN
      __pycache__/shadowdice.cpython-38.pyc
  2. 1
      aliases.csv
  3. 7
      help.html
  4. 7
      metadata.ini
  5. 4
      privileges.csv
  6. 120
      shadowdice.py

@ -1,2 +1,3 @@
alias,command alias,command
predge,(preedge) predge,(preedge)
pass,(initpass)

1 alias command
2 predge (preedge)
3 pass (initpass)

@ -1,5 +1,10 @@
All commands can be run by typing it in the chat or privately messaging JJMumbleBot.<br> All commands can be run by typing it in the chat or privately messaging JJMumbleBot.<br>
<b>!init</b>: Roll init dice <i>!init 4 11</i> will roll 4d6+11<br> <b>!addinit</b>: Roll init for a user <i>!init 4 11 Malta</i> will add Malta with 4d6+11<br>
<b>!listinit</b>: List all inits in the init DB<br>
<b>!rollinit</b>: Rolls the inits for all of the users, and outputs it<br>
<b>!initpass</b>: Subtracts 10 from all inits, minimum 0<br>
<b>!interupt</b>: Subtracts an amount from a single user's init, wont work if you try to subtract more init from the character than they have <i>!interupt Malta 7</i> will subtract 7 init from Malta<br>
<b>!clearinit</b>: Deletes all of the initiatives<br>
<b>!srun</b>: Roll a bunch of dice, count successes and ones <i>!srun 12</i> will roll a pool of 12 dice<br> <b>!srun</b>: Roll a bunch of dice, count successes and ones <i>!srun 12</i> will roll a pool of 12 dice<br>
<b>!preedge</b>: Roll a pool with exploding 6s, counts successes, ones, and explosions <i>!preedge 12</i> will roll a poll of 12 dice<br> <b>!preedge</b>: Roll a pool with exploding 6s, counts successes, ones, and explosions <i>!preedge 12</i> will roll a poll of 12 dice<br>
<b>!assensing</b>: Prints the Shadowrun assensing table<br> <b>!assensing</b>: Prints the Shadowrun assensing table<br>

@ -4,7 +4,12 @@ PluginName = Shadow Dice
PluginDescription = A plugin for rolling dice in Shadowrun 5e. PluginDescription = A plugin for rolling dice in Shadowrun 5e.
PluginLanguage = EN PluginLanguage = EN
PluginCommands: [ PluginCommands: [
"init", "rollinit",
"addinit",
"listinit",
"initpass",
"clearinit",
"interupt",
"srun", "srun",
"preedge", "preedge",
"assensing", "assensing",

@ -1,5 +1,7 @@
command,level command,level
init,1 rollinit,1
addinit,1
listinit,1
srun,1 srun,1
preedge,1 preedge,1
assensing,1 assensing,1

1 command level
2 init rollinit 1
3 addinit 1
4 listinit 1
5 srun 1
6 preedge 1
7 assensing 1

@ -7,6 +7,7 @@ from JJMumbleBot.settings import global_settings as gs
from JJMumbleBot.lib.resources.strings import * from JJMumbleBot.lib.resources.strings import *
import os import os
import random import random
import sqlite3
class Plugin(PluginBase): class Plugin(PluginBase):
@ -16,6 +17,11 @@ class Plugin(PluginBase):
self.plugin_name = os.path.basename(__file__).rsplit('.')[0] self.plugin_name = os.path.basename(__file__).rsplit('.')[0]
self.metadata = PluginUtilityService.process_metadata(f'plugins/extensions/{self.plugin_name}') self.metadata = PluginUtilityService.process_metadata(f'plugins/extensions/{self.plugin_name}')
self.plugin_cmds = loads(self.metadata.get(C_PLUGIN_INFO, P_PLUGIN_CMDS)) 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 self.is_running = True
log( log(
INFO, INFO,
@ -25,6 +31,11 @@ class Plugin(PluginBase):
) )
def quit(self): 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 self.is_running = False
log( log(
INFO, INFO,
@ -41,12 +52,110 @@ class Plugin(PluginBase):
if not self.is_running: if not self.is_running:
self.__init__() self.__init__()
def cmd_init(self, data): def cmd_addinit(self,data):
all_data = data.message.strip().split() all_data = data.message.strip().split()
try: try:
number_of_dice = int(all_data[1]) number_of_dice = int(all_data[1])
init_bonus = int(all_data[2]) init_bonus = int(all_data[2])
ret_text = "<br><font color='red'>Init Roll:</font><br><font colour='blue'>" 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]) + "<br>"
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) + "<br>"
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 = "<br><font color='red'>Init For " + str(row[3]) + ":</font><br>"
result = 0 result = 0
for i in range(number_of_dice): for i in range(number_of_dice):
random.seed(int.from_bytes(os.urandom(8), byteorder="big")) random.seed(int.from_bytes(os.urandom(8), byteorder="big"))
@ -54,8 +163,11 @@ class Plugin(PluginBase):
result = result + this_die result = result + this_die
ret_text += f"{this_die} + " ret_text += f"{this_die} + "
result = result + init_bonus result = result + init_bonus
init.execute("UPDATE inits SET total = :result WHERE name = :name", {"result": result, "name": row[3]})
ret_text += f" {init_bonus} </font><br><font color='yellow'> {result}</font>" ret_text += f" {init_bonus} </font><br><font color='yellow'> {result}</font>"
gs.gui_service.quick_gui(ret_text, text_type='header', box_align='left') gs.gui_service.quick_gui(ret_text, text_type='header', box_align='left')
init_db.commit()
init_db.close()
return return
except IndexError: except IndexError:
log(ERROR, CMD_INVALID_CUSTOM_ROLL, log(ERROR, CMD_INVALID_CUSTOM_ROLL,
@ -68,7 +180,7 @@ class Plugin(PluginBase):
all_data = data.message.strip().split() all_data = data.message.strip().split()
try: try:
number_of_dice = int(all_data[1]) number_of_dice = int(all_data[1])
ret_text = "<br><font color='red'>Die Pool:</font><br><font colour='blue'>" ret_text = "<br><font color='red'>Die Pool:</font><br>"
successes = 0 successes = 0
ones = 0 ones = 0
for i in range(number_of_dice): for i in range(number_of_dice):
@ -93,7 +205,7 @@ class Plugin(PluginBase):
all_data = data.message.strip().split() all_data = data.message.strip().split()
try: try:
number_of_dice = int(all_data[1]) number_of_dice = int(all_data[1])
ret_text = "<br><font color='red'>Die Pool:</font><br><font colour='blue'>" ret_text = "<br><font color='red'>Die Pool:</font><br>"
successes = 0 successes = 0
ones = 0 ones = 0
explosions = 0 explosions = 0

Loading…
Cancel
Save