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
aeb9e40a
authored
2016-06-16 17:35:52 +0000
by
Barry
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Added new ping functionality to track a reflex server.
1 parent
8d971f89
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
0 deletions
data.py
db.sqlite3
hellsbot.py
data.py
View file @
aeb9e40
...
...
@@ -112,6 +112,29 @@ def db_add_minigame(member_id, minigame_name, state):
WHERE member_id = ? AND minigame_name = ?;"""
,
(
state
,
member_id
,
minigame_name
))
conn
.
commit
()
def
db_get_pings
():
conn
=
sqlite3
.
connect
(
'db.sqlite3'
)
c
=
conn
.
cursor
()
result
=
c
.
execute
(
"SELECT * FROM pings;"
)
.
fetchall
()
conn
.
close
()
results
=
[]
for
row
in
result
:
results
.
append
(
dict_factory
(
c
,
row
))
return
results
def
db_update_ping
(
ping_id
,
last_ping
):
conn
=
sqlite3
.
connect
(
'db.sqlite3'
)
c
=
conn
.
cursor
()
if
not
last_ping
:
outage
=
datetime
.
datetime
.
now
()
.
strftime
(
'
%
Y/
%
m/
%
d
%
H:
%
M:
%
S'
)
c
.
execute
(
"UPDATE pings SET last_ping = ?, last_outage = ? WHERE ping_id = ?;"
,
(
last_ping
,
outage
,
ping_id
))
conn
.
commit
()
else
:
c
.
execute
(
"UPDATE pings SET last_ping = ?, average_ping = (average_ping + ?) / 2 WHERE ping_id = ?;"
,
(
last_ping
,
last_ping
,
ping_id
))
conn
.
commit
()
conn
.
close
()
def
db_get_minigame_state
(
member_id
,
minigame_name
):
conn
=
sqlite3
.
connect
(
'db.sqlite3'
)
c
=
conn
.
cursor
()
...
...
db.sqlite3
View file @
aeb9e40
No preview for this file type
hellsbot.py
View file @
aeb9e40
...
...
@@ -27,8 +27,12 @@ import wolframalpha
import
sqlite3
from
blackjack
import
Blackjack
import
data
import
pyping
from
pankration
import
Pankration
,
HuntResponse
,
Jobs
,
Action
,
MagicResistAction
,
MissAction
,
AttackAction
,
DefeatAction
,
TemperamentPosture
,
TemperamentAttitude
import
subprocess
VERSION
=
2.3
quitting
=
False
...
...
@@ -178,6 +182,35 @@ def search_google_images(query, animated=False):
return
"boo you fail.."
def
ping
(
hostname
,
timeout
):
ping_response
=
subprocess
.
Popen
([
"/bin/ping"
,
"-c1"
,
"-w100"
,
hostname
],
stdout
=
subprocess
.
PIPE
)
.
stdout
.
read
()
log
(
ping_response
)
matches
=
re
.
match
(
'.*time=([0-9]+) ms.*'
,
ping_response
,
re
.
DOTALL
)
if
matches
:
return
matches
.
group
(
1
)
else
:
return
False
def
check_pings
():
ping_list
=
data
.
db_get_pings
()
new_ping
=
ping
(
ping_list
[
0
]
.
get
(
'ip_address'
),
1000
)
if
new_ping
:
log
(
"New Ping: {}"
.
format
(
new_ping
))
data
.
db_update_ping
(
ping_list
[
0
]
.
get
(
'ping_id'
),
new_ping
)
for
channel
in
client
.
get_all_channels
():
if
channel
.
id
==
'193028170184785920'
:
# Reflex channel
send_message
(
client
,
channel
,
"{} - {}ms Average: {}ms"
.
format
(
ping_list
[
0
]
.
get
(
'ip_address'
),
new_ping
,
ping_list
[
0
]
.
get
(
'average_ping'
)))
break
else
:
for
member
in
client
.
get_all_members
():
if
member
.
id
==
'122079633796497409'
:
send_message
(
client
,
member
,
"Outage! {} - {}ms Average: {}ms"
.
format
(
ping_list
[
0
]
.
get
(
'ip_address'
),
new_ping
,
ping_list
[
0
]
.
get
(
'average_ping'
)))
break
data
.
db_update_ping
(
ping_list
[
0
]
.
get
(
'ping_id'
),
False
)
def
check_msg_queue
(
client
):
messages
=
data
.
db_get_messages
()
if
messages
:
...
...
@@ -1391,7 +1424,11 @@ def check_arena():
### END PANKRATION
def
start_timer
(
client
):
needs_loot
=
True
time_to_ping
=
True
while
not
quitting
:
if
time_to_ping
:
check_pings
()
time_to_ping
=
not
time_to_ping
if
not
battle_in_progress
:
thread
.
start_new_thread
(
check_arena
,
())
...
...
Please
register
or
sign in
to post a comment