Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Barry
/
discordbot
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
71937a50
authored
2016-02-21 09:53:13 +0000
by
Barry
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Added some interfaces to the pankration and db
1 parent
9f06bad8
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
0 deletions
data.py
db.sqlite3
hellsbot.py
data.py
View file @
71937a5
...
...
@@ -2,6 +2,7 @@ import operator
import
sqlite3
import
datetime
import
logging
import
pickle
def
byteify
(
input
):
...
...
@@ -236,6 +237,36 @@ def db_get_all_members():
members_list
.
append
(
dict_factory
(
c
,
member
))
return
members_list
def
db_get_pankration_record
(
member_id
):
# Do a lookup by ID, if it's found but the name doesn't match then add a row to aliases with the previous name and change the member name
pan_record
=
sqlite3
.
connect
(
'db.sqlite3'
)
c
=
pan_record
.
cursor
()
result
=
None
result
=
c
.
execute
(
"SELECT * FROM pankration WHERE member_id = ?;"
,
(
member_id
,))
.
fetchone
()
pan_record
.
close
()
return
dict_factory
(
c
,
result
)
def
db_add_monster
(
member_id
,
monster
):
pan_record
=
db_get_pankration_record
(
member_id
)
log
(
"{}"
.
format
(
member_id
))
conn
=
sqlite3
.
connect
(
'db.sqlite3'
)
c
=
conn
.
cursor
()
db_state
=
c
.
execute
(
"SELECT monster_inventory FROM pankration WHERE member_id = ?;"
,
(
member_id
,))
.
fetchone
()
if
not
db_state
:
c
.
execute
(
"""INSERT INTO pankration(member_id, wins, losses, monster_inventory)
VALUES(?, ?, ?, ?);"""
,
(
member_id
,
0
,
0
,
pickle
.
dumps
([
monster
])))
conn
.
commit
()
else
:
log
(
db_state
)
inv
=
str
(
db_state
[
0
])
log
(
inv
)
monster_inventory
=
pickle
.
loads
(
inv
)
monster_inventory
.
append
(
monster
)
c
.
execute
(
"""UPDATE pankration SET monster_inventory = ?
WHERE member_id = ?;"""
,
(
pickle
.
dumps
(
monster_inventory
),
member_id
))
conn
.
commit
()
def
db_get_member
(
discord_id
=
None
,
username
=
None
):
# Do a lookup by ID, if it's found but the name doesn't match then add a row to aliases with the previous name and change the member name
member_conn
=
sqlite3
.
connect
(
'db.sqlite3'
)
...
...
db.sqlite3
View file @
71937a5
No preview for this file type
hellsbot.py
View file @
71937a5
...
...
@@ -85,6 +85,7 @@ registered_commands = {'!help': 'do_help', '!commands': 'do_help',
'!rigged'
:
'do_rigged'
,
'!listzones'
:
'do_list_zones'
,
'!huntmonster'
:
'do_hunt_monster'
,
'!listmonster'
:
'do_list_monsters'
,
}
...
...
@@ -1014,12 +1015,24 @@ def do_rigged(client, message_parts, message):
send_message
(
client
,
message
.
channel
,
":musical_note: {} :musical_note:"
.
format
(
random
.
choice
(
lines
)))
return
def
do_list_monsters
(
client
,
message_parts
,
message
):
member
=
data
.
db_get_member
(
message
.
author
.
id
)
log
(
member
)
monster_data
=
data
.
db_get_pankration_record
(
member
[
'member_id'
])
if
monster_data
:
monsters
=
pickle
.
loads
(
str
(
monster_data
[
'monster_inventory'
]))
send_message
(
client
,
message
.
channel
,
"
\n\n
"
.
join
(
str
(
monster
)
for
monster
in
monsters
))
else
:
send_message
(
client
,
message
.
channel
,
'You have no monsters.'
)
def
do_hunt_monster
(
client
,
message_parts
,
message
):
p
=
Pankration
()
hunt_response
=
p
.
hunt_monster
(
' '
.
join
(
message_parts
))
str_out
=
hunt_response
.
message
+
"
\n\n
"
if
hunt_response
.
result
==
HuntResponse
.
SUCCESS
:
monster
=
hunt_response
.
monster
member
=
data
.
db_get_member
(
message
.
author
.
id
)
data
.
db_add_monster
(
member
[
'member_id'
],
monster
)
str_out
+=
str
(
monster
)
send_message
(
client
,
message
.
channel
,
str_out
)
...
...
Please
register
or
sign in
to post a comment