Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
cbdiscord
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Geovanny E. Vera Pazmino
cbdiscord
Commits
79eee266
Commit
79eee266
authored
May 30, 2020
by
Geovanny
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added timeout for sessions
parent
7446f00d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
1 deletion
+21
-1
.gitignore
.gitignore
+1
-0
bot.py
discord/bot.py
+5
-1
timed_dict.py
discord/util/timed_dict.py
+15
-0
No files found.
.gitignore
View file @
79eee266
...
@@ -3,6 +3,7 @@ server/node_modules/
...
@@ -3,6 +3,7 @@ server/node_modules/
server/.env
server/.env
discord/.env
discord/.env
discord/__pycache__
discord/__pycache__
discord/testy.py
web/node_modules
web/node_modules
*.pyc
*.pyc
__pycache__
__pycache__
...
...
discord/bot.py
View file @
79eee266
...
@@ -12,15 +12,18 @@ from house.war.manager import WarManager
...
@@ -12,15 +12,18 @@ from house.war.manager import WarManager
from
util.command_error_handler
import
CommandErrorHandler
from
util.command_error_handler
import
CommandErrorHandler
from
util.help
import
EditedMinimalHelpCommand
,
PaginatedHelpCommand
from
util.help
import
EditedMinimalHelpCommand
,
PaginatedHelpCommand
from
util.api_requests
import
Api
from
util.api_requests
import
Api
from
util.timed_dict
import
TimedDict
from
settings
import
DISCORD_TOKEN
from
settings
import
DISCORD_TOKEN
COOKIE_LIFETIME
=
18000
;
class
ConqBot
(
commands
.
Bot
):
class
ConqBot
(
commands
.
Bot
):
def
__init__
(
self
,
command_prefix
=
'>'
):
def
__init__
(
self
,
command_prefix
=
'>'
):
super
()
.
__init__
(
super
()
.
__init__
(
command_prefix
=
command_prefix
,
command_prefix
=
command_prefix
,
help_command
=
EditedMinimalHelpCommand
())
help_command
=
EditedMinimalHelpCommand
())
self
.
id_to_session
=
{}
self
.
id_to_session
=
TimedDict
()
self
.
static_help_command
=
self
.
help_command
self
.
static_help_command
=
self
.
help_command
command_impl
=
self
.
help_command
.
_command_impl
command_impl
=
self
.
help_command
.
_command_impl
...
@@ -38,6 +41,7 @@ class ConqBot(commands.Bot):
...
@@ -38,6 +41,7 @@ class ConqBot(commands.Bot):
return
self
.
id_to_session
[
user
.
id
]
return
self
.
id_to_session
[
user
.
id
]
new_session
=
Session
()
new_session
=
Session
()
await
Api
.
postSession
(
'/user/d-login'
,
{
"discordId"
:
user
.
id
},
new_session
);
await
Api
.
postSession
(
'/user/d-login'
,
{
"discordId"
:
user
.
id
},
new_session
);
self
.
id_to_session
.
set_key
(
user
.
id
,
new_session
,
COOKIE_LIFETIME
)
self
.
id_to_session
[
user
.
id
]
=
new_session
self
.
id_to_session
[
user
.
id
]
=
new_session
return
new_session
return
new_session
...
...
discord/util/timed_dict.py
0 → 100644
View file @
79eee266
import
time
class
TimedDict
(
dict
):
def
__init__
(
self
):
self
.
__table
=
{}
def
set_key
(
self
,
key
,
value
,
timeout
=
1
):
# add timer to table
self
.
__table
[
key
]
=
time
.
time
()
+
timeout
;
super
(
TimedDict
,
self
)
.
__setitem__
(
key
,
value
);
def
__contains__
(
self
,
key
):
return
(
key
in
self
.
__table
)
and
(
time
.
time
()
<
self
.
__table
.
get
(
key
))
def
__iter__
(
self
):
for
item
in
dict
.
__iter__
(
self
):
if
time
.
time
()
<
self
.
__table
.
get
(
item
):
yield
item
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment