Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
haugebot
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dnns01
haugebot
Commits
fc834d19
Commit
fc834d19
authored
4 years ago
by
dnns01
Browse files
Options
Downloads
Patches
Plain Diff
Added debug messages to figure out, why the hell the loops are not working as expected!
parent
d59b151a
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
hausgeist.py
+6
-2
6 additions, 2 deletions
hausgeist.py
info_cog.py
+12
-5
12 additions, 5 deletions
info_cog.py
pipi_cog.py
+13
-6
13 additions, 6 deletions
pipi_cog.py
with
31 additions
and
13 deletions
hausgeist.py
+
6
−
2
View file @
fc834d19
import
asyncio
import
logging
import
os
from
abc
import
ABC
...
...
@@ -10,6 +12,8 @@ from info_cog import InfoCog
from
pipi_cog
import
PipiCog
from
vote_cog
import
VoteCog
logging
.
basicConfig
(
level
=
logging
.
INFO
,
filename
=
'
hausgeist.log
'
)
load_dotenv
()
IRC_TOKEN
=
os
.
getenv
(
"
IRC_TOKEN
"
)
CLIENT_ID
=
os
.
getenv
(
"
CLIENT_ID
"
)
...
...
@@ -51,8 +55,8 @@ class HaugeBot(commands.Bot, ABC):
async
def
event_ready
(
self
):
print
(
'
Logged in
'
)
a
wait
self
.
pipi
_cog
.
start_pipimeter
_loop
()
a
wait
self
.
info
_cog
.
start_info
_loop
()
a
syncio
.
create_task
(
self
.
info
_cog
.
info
_loop
()
)
a
syncio
.
create_task
(
self
.
pipi
_cog
.
pipimeter
_loop
()
)
@staticmethod
def
get_percentage
(
part
,
total
):
...
...
This diff is collapsed.
Click to expand it.
info_cog.py
+
12
−
5
View file @
fc834d19
import
asyncio
import
json
import
logging
import
os
import
random
from
datetime
import
datetime
from
twitchio.ext
import
commands
...
...
@@ -11,7 +13,7 @@ class InfoCog:
def
__init__
(
self
,
bot
):
self
.
bot
=
bot
self
.
info_file
=
os
.
getenv
(
"
INFO_JSON
"
)
self
.
INFO_LOOP
=
in
t
(
os
.
getenv
(
"
INFO_LOOP
"
))
self
.
INFO_LOOP
=
floa
t
(
os
.
getenv
(
"
INFO_LOOP
"
))
self
.
INFO_COLOR
=
os
.
getenv
(
"
INFO_COLOR
"
)
self
.
info
=
[]
self
.
load_info
()
...
...
@@ -21,19 +23,24 @@ class InfoCog:
info_file
=
open
(
self
.
info_file
,
mode
=
'
r
'
)
self
.
info
=
json
.
load
(
info_file
)
pass
async
def
start_info_loop
(
self
):
asyncio
.
create_task
(
self
.
info_loop
())
async
def
info_loop
(
self
):
"""
Send !pipimeter into the chat every x Minutes. Also check, whether the stream was offline for x Minutes.
If this is true, reset the pipi counter, as you can assume, that the stream recently started.
"""
logging
.
log
(
logging
.
INFO
,
f
"
Info loop started.
{
datetime
.
now
()
}
{
self
}
"
)
while
True
:
logging
.
log
(
logging
.
INFO
,
f
"
Inside Info loop. Sleep for
{
self
.
INFO_LOOP
}
minutes.
{
datetime
.
now
()
}
{
self
}
"
)
await
asyncio
.
sleep
(
self
.
INFO_LOOP
*
60
)
logging
.
log
(
logging
.
INFO
,
f
"
Inside Info loop finished sleeping now.
{
datetime
.
now
()
}
{
self
}
"
)
if
await
self
.
bot
.
stream
():
logging
.
log
(
logging
.
INFO
,
f
"
Inside Info loop. Stream is online, so send a message now!!!
{
datetime
.
now
()
}
{
self
}
"
)
channel
=
self
.
bot
.
channel
()
message
=
f
"
Psssst... wusstest du eigentlich schon,
{
random
.
choice
(
self
.
info
)
}
"
await
self
.
bot
.
send_me
(
channel
,
message
,
self
.
INFO_COLOR
)
logging
.
log
(
logging
.
INFO
,
f
"
Inside Info loop. Ooooookay, Loop ended, let
'
s continue with the next round!!!
{
datetime
.
now
()
}
{
self
}
"
)
This diff is collapsed.
Click to expand it.
pipi_cog.py
+
13
−
6
View file @
fc834d19
import
asyncio
import
logging
import
os
from
datetime
import
datetime
from
twitchio.dataclasses
import
Message
from
twitchio.ext
import
commands
...
...
@@ -21,12 +23,6 @@ class PipiCog:
self
.
pipi_task
=
None
self
.
pipi_votes
=
{}
async
def
start_pipimeter_loop
(
self
):
# Wait for one minute to avoid this loop and the info loop to post directly after each other
await
asyncio
.
sleep
(
60
)
asyncio
.
create_task
(
self
.
pipimeter_loop
())
async
def
notify_pipi
(
self
,
ctx
,
use_timer
=
True
,
message
=
None
):
"""
Write a message in chat, if there hasn
'
t been a notification since DELAY seconds.
"""
...
...
@@ -73,12 +69,20 @@ class PipiCog:
"""
Send !pipimeter into the chat every x Minutes. Also check, whether the stream was offline for x Minutes.
If this is true, reset the pipi counter, as you can assume, that the stream recently started.
"""
logging
.
log
(
logging
.
INFO
,
f
"
Pipi loop started To have an offset from Info loop, wait for one minute.
{
datetime
.
now
()
}
{
self
}
"
)
offline_since
=
0
await
asyncio
.
sleep
(
60
)
while
True
:
logging
.
log
(
logging
.
INFO
,
f
"
Inside Pipi loop. Sleep for
{
self
.
PIPIMETER_LOOP
}
minutes.
{
datetime
.
now
()
}
{
self
}
"
)
await
asyncio
.
sleep
(
self
.
PIPIMETER_LOOP
*
60
)
logging
.
log
(
logging
.
INFO
,
f
"
Inside Pipi loop finished sleeping now.
{
datetime
.
now
()
}
{
self
}
"
)
if
await
self
.
bot
.
stream
():
logging
.
log
(
logging
.
INFO
,
f
"
Inside Pipi loop. Stream is online, so check for threshold!!!
{
datetime
.
now
()
}
{
self
}
"
)
if
offline_since
>=
self
.
RESET_THRESHOLD
:
self
.
pipi_votes
=
{}
offline_since
=
0
...
...
@@ -90,6 +94,9 @@ class PipiCog:
else
:
offline_since
+=
self
.
PIPIMETER_LOOP
logging
.
log
(
logging
.
INFO
,
f
"
Inside Pipi loop. Ooooookay, Loop ended, let
'
s continue with the next round!!!
{
datetime
.
now
()
}
{
self
}
"
)
@commands.command
(
name
=
"
pipi
"
,
aliases
=
[
"
Pipi
"
])
async
def
cmd_pipi
(
self
,
ctx
):
"""
User mentioned there is a need to go to toilet.
"""
...
...
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