Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
maubot-ethzlunch
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
isgphys
maubot-ethzlunch
Commits
5bace921
Unverified
Commit
5bace921
authored
4 years ago
by
Dominik George
Browse files
Options
Downloads
Patches
Plain Diff
Move handling of default timezone to instance and db code
parent
5fc92aa6
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
reminder/bot.py
+5
-0
5 additions, 0 deletions
reminder/bot.py
reminder/db.py
+2
-2
2 additions, 2 deletions
reminder/db.py
reminder/util.py
+2
-5
2 additions, 5 deletions
reminder/util.py
with
9 additions
and
7 deletions
reminder/bot.py
+
5
−
0
View file @
5bace921
...
@@ -51,6 +51,11 @@ class ReminderBot(Plugin):
...
@@ -51,6 +51,11 @@ class ReminderBot(Plugin):
bc
=
self
.
config
[
"
base_command
"
]
bc
=
self
.
config
[
"
base_command
"
]
self
.
base_command
=
bc
[
0
]
if
isinstance
(
bc
,
list
)
else
bc
self
.
base_command
=
bc
[
0
]
if
isinstance
(
bc
,
list
)
else
bc
self
.
base_aliases
=
tuple
(
bc
)
if
isinstance
(
bc
,
list
)
else
(
bc
,)
self
.
base_aliases
=
tuple
(
bc
)
if
isinstance
(
bc
,
list
)
else
(
bc
,)
try
:
self
.
default_timezone
=
pytz
.
timezone
(
self
.
config
[
"
timezone
"
])
except
pytz
.
UnknownTimeZoneError
:
self
.
log
.
warning
(
f
"
Unknown default timezone
{
self
.
config
[
'
timezone
'
]
}
"
)
self
.
default_timezone
=
pytz
.
UTC
async
def
stop
(
self
)
->
None
:
async
def
stop
(
self
)
->
None
:
self
.
reminder_loop_task
.
cancel
()
self
.
reminder_loop_task
.
cancel
()
...
...
This diff is collapsed.
Click to expand it.
reminder/db.py
+
2
−
2
View file @
5bace921
...
@@ -70,7 +70,7 @@ class ReminderDatabase:
...
@@ -70,7 +70,7 @@ class ReminderDatabase:
tx
.
execute
(
self
.
timezone
.
insert
().
values
(
user_id
=
user_id
,
timezone
=
tz
.
zone
))
tx
.
execute
(
self
.
timezone
.
insert
().
values
(
user_id
=
user_id
,
timezone
=
tz
.
zone
))
self
.
tz_cache
[
user_id
]
=
tz
self
.
tz_cache
[
user_id
]
=
tz
def
get_timezone
(
self
,
user_id
:
UserID
)
->
Optional
[
pytz
.
timezone
]:
def
get_timezone
(
self
,
user_id
:
UserID
,
default_tz
:
Optional
[
pytz
.
timezone
]
)
->
Optional
[
pytz
.
timezone
]:
try
:
try
:
return
self
.
tz_cache
[
user_id
]
return
self
.
tz_cache
[
user_id
]
except
KeyError
:
except
KeyError
:
...
@@ -79,7 +79,7 @@ class ReminderDatabase:
...
@@ -79,7 +79,7 @@ class ReminderDatabase:
try
:
try
:
self
.
tz_cache
[
user_id
]
=
pytz
.
timezone
(
next
(
rows
)[
0
])
self
.
tz_cache
[
user_id
]
=
pytz
.
timezone
(
next
(
rows
)[
0
])
except
(
pytz
.
UnknownTimeZoneError
,
StopIteration
,
IndexError
):
except
(
pytz
.
UnknownTimeZoneError
,
StopIteration
,
IndexError
):
self
.
tz_cache
[
user_id
]
=
pytz
.
UTC
self
.
tz_cache
[
user_id
]
=
default_tz
or
pytz
.
UTC
return
self
.
tz_cache
[
user_id
]
return
self
.
tz_cache
[
user_id
]
def
set_locales
(
self
,
user_id
:
UserID
,
locales
:
List
[
str
])
->
None
:
def
set_locales
(
self
,
user_id
:
UserID
,
locales
:
List
[
str
])
->
None
:
...
...
This diff is collapsed.
Click to expand it.
reminder/util.py
+
2
−
5
View file @
5bace921
...
@@ -44,13 +44,10 @@ class DateArgument(Argument):
...
@@ -44,13 +44,10 @@ class DateArgument(Argument):
def
match
(
self
,
val
:
str
,
evt
:
MessageEvent
=
None
,
instance
:
'
ReminderBot
'
=
None
def
match
(
self
,
val
:
str
,
evt
:
MessageEvent
=
None
,
instance
:
'
ReminderBot
'
=
None
)
->
Tuple
[
str
,
Optional
[
datetime
]]:
)
->
Tuple
[
str
,
Optional
[
datetime
]]:
try
:
tz
=
pytz
.
UTC
tz
=
pytz
.
timezone
(
instance
.
config
[
"
timezone
"
])
except
(
pytz
.
UnknownTimeZoneError
,
StopIteration
,
IndexError
):
tz
=
pytz
.
UTC
use_locales
=
[
locales
[
"
en_iso
"
]]
use_locales
=
[
locales
[
"
en_iso
"
]]
if
instance
:
if
instance
:
tz
=
instance
.
db
.
get_timezone
(
evt
.
sender
)
tz
=
instance
.
db
.
get_timezone
(
evt
.
sender
,
instance
.
default_timezone
)
locale_ids
=
instance
.
db
.
get_locales
(
evt
.
sender
)
locale_ids
=
instance
.
db
.
get_locales
(
evt
.
sender
)
use_locales
=
[
locales
[
id
]
for
id
in
locale_ids
if
id
in
locales
]
use_locales
=
[
locales
[
id
]
for
id
in
locale_ids
if
id
in
locales
]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment