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
f3b26e30
authored
2016-01-18 11:22:30 +0000
by
Barry
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Database calls added for jokes.
1 parent
976ae1a2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
21 deletions
db.sqlite3
hellsbot.py
members.json
db.sqlite3
View file @
f3b26e3
No preview for this file type
hellsbot.py
View file @
f3b26e3
...
...
@@ -16,8 +16,11 @@ import simplejson as json
from
collections
import
defaultdict
from
nltk.tag
import
pos_tag
import
wolframalpha
import
sqlite3
VERSION
=
1.5
VERSION
=
1.6
conn
=
sqlite3
.
connect
(
'db.sqlite3'
)
member_status
=
'members.json'
deliveries_file
=
'deliveries.json'
...
...
@@ -620,38 +623,36 @@ Stuff:
if
message
.
content
.
startswith
(
'!addjoke'
):
try
:
json_data
=
open
(
joke_file
)
.
read
()
data
=
json
.
loads
(
json_data
)
except
ValueError
:
data
=
[]
if
not
data
:
data
=
[]
try
:
if
'aa737a5846'
in
message
.
content
[
9
:]:
joke
=
message
.
content
[
9
:]
if
'aa737a5846'
in
joke
:
client
.
send_message
(
message
.
channel
,
'{} you stop it, you are a pedofile, stop looking at little girls.'
.
format
(
message
.
author
.
mention
()))
return
data
.
append
(
byteify
(
message
.
content
[
9
:]))
jdata
=
json
.
dumps
(
data
,
ensure_ascii
=
False
)
date_added
=
datetime
.
datetime
.
now
()
.
strftime
(
'
%
Y/
%
m/
%
d
%
H:
%
M:
%
S'
)
c
=
conn
.
cursor
()
c
.
execute
(
"INSERT INTO jokes (joke) VALUES (?)"
,
(
joke
,))
conn
.
commit
()
print
(
"Added joke"
)
except
Exception
as
e
:
print
e
.
message
client
.
send_message
(
message
.
channel
,
'Your shitty joke has been rejected {}.'
.
format
(
message
.
author
.
mention
()))
return
open
(
joke_file
,
'wb+'
)
.
write
(
jdata
.
encode
(
'utf8'
))
client
.
send_message
(
message
.
channel
,
'Your shitty joke has been added {}.'
.
format
(
message
.
author
.
mention
()))
return
if
message
.
content
.
startswith
(
'!joke'
):
data
=
None
joke
=
None
try
:
json_data
=
open
(
joke_file
)
.
read
()
data
=
json
.
loads
(
json_data
)
except
ValueError
:
c
=
conn
.
cursor
()
joke
=
c
.
execute
(
"SELECT joke FROM jokes ORDER BY RANDOM() LIMIT 1;"
)
.
fetchone
()[
0
]
print
(
joke
)
except
Exception
as
e
:
print
(
e
)
pass
if
not
data
:
client
.
send_message
(
message
.
channel
,
'Try adding a joke with "!addjoke <joke>" {}!'
.
format
(
message
.
author
.
mention
()))
if
not
joke
:
client
.
send_message
(
message
.
channel
,
'Try adding a joke with "!addjoke <joke>" {}!'
.
format
(
message
.
author
.
mention
()))
else
:
client
.
send_message
(
message
.
channel
,
'{} {}'
.
format
(
message
.
author
.
mention
(),
random
.
choice
(
data
)
.
encode
(
'utf-8'
,
errors
=
'ignore'
)))
client
.
send_message
(
message
.
channel
,
'{} {}'
.
format
(
message
.
author
.
mention
(),
byteify
(
joke
)))
return
if
message
.
content
.
startswith
(
'!secret'
):
client
.
send_message
(
message
.
channel
,
'git gud {}! My source is here: http://git.savsoul.com/barry/discordbot
\n
Version: {}'
.
format
(
message
.
author
.
mention
(),
VERSION
))
...
...
@@ -685,6 +686,7 @@ while retries < 1000:
client
.
run
()
except
KeyboardInterrupt
:
conn
.
close
quit
()
except
:
retries
+=
1
...
...
members.json
View file @
f3b26e3
This diff is collapsed.
Click to expand it.
Please
register
or
sign in
to post a comment