@ -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,12 +52,110 @@ class Plugin(PluginBase):
if not self . is_running :
self . __init__ ( )
def cmd_init ( self , data ) :
def cmd_add init ( self , data ) :
all_data = data . message . strip ( ) . split ( )
try :
number_of_dice = int ( all_data [ 1 ] )
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
for i in range ( number_of_dice ) :
random . seed ( int . from_bytes ( os . urandom ( 8 ) , byteorder = " big " ) )
@ -54,8 +163,11 @@ class Plugin(PluginBase):
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 } </font><br><font color= ' yellow ' > { result } </font> "
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 = " <br><font color= ' red ' >Die Pool:</font><br><font colour= ' blue ' > "
ret_text = " <br><font color= ' red ' >Die Pool:</font><br> "
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 = " <br><font color= ' red ' >Die Pool:</font><br><font colour= ' blue ' > "
ret_text = " <br><font color= ' red ' >Die Pool:</font><br> "
successes = 0
ones = 0
explosions = 0