Skip to content

Commit dd36f22

Browse files
author
lagaffe
committed
error handeling in topic plugin
1 parent 81746a8 commit dd36f22

4 files changed

Lines changed: 70 additions & 68 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ with the user names of the sudoers in the users array (you can allways add some
4747

4848
For a minimal setup, add `--local` so that lechbot won't try to poll from twitter or other distant APIs.
4949

50+
Il peut être nécessaire de mettre a jour yt-dlp pour que !motd fonctionne correctement
51+
5052
### Connect to irc
5153

5254
`$ python lechbot.py --irc [ --debug ]`

ircbot/persist.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import json
22
import logging
33
from copy import deepcopy
4+
from os import path
45
from fcntl import LOCK_EX, LOCK_UN, flock
56

67
logger = logging.getLogger()
78

89

910
class Persistent:
1011
def __init__(self, file):
11-
self.file = file
12+
self.file = path.join("data", file)
13+
self.db = None
14+
self._initial = self.db
1215

1316
def __enter__(self):
1417
try:
@@ -18,11 +21,12 @@ def __enter__(self):
1821
flock(self.fd, LOCK_EX)
1922
try:
2023
self.db = json.load(self.fd)
24+
self._initial = deepcopy(self.db)
2125
logger.debug("Loaded " + repr(self.db) + " from " + self.file)
2226
except:
2327
logger.exception("Cannot load from " + self.file)
2428
self.db = {}
25-
self._initial = deepcopy(self.db)
29+
2630
return self.db
2731

2832
def __exit__(self, *args, **kwargs):

plugins/topic.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import re
22
from datetime import datetime
3-
from time import time
3+
from time import time, sleep
44

55
from yt_dlp import YoutubeDL
66

@@ -34,9 +34,13 @@ def make_topic(self, msg, new_topic=None, new_music=None):
3434

3535
def find_title(self, url):
3636
with YoutubeDL() as ydl:
37-
info_dict = ydl.extract_info(url, download=False)
38-
video_title = info_dict.get("title", None)
39-
return video_title
37+
try:
38+
info_dict = ydl.extract_info(url, download=False)
39+
video_title = info_dict.get("title", None)
40+
return video_title
41+
except:
42+
self.bot.log.exception("could not find title")
43+
return None
4044

4145
@BotPlugin.command(r"\!motd +(https?://[^ ]+)")
4246
async def music_of_the_day(self, msg):
@@ -63,14 +67,14 @@ async def music_of_the_day(self, msg):
6367
except ApiError as e:
6468
if e.error_type == "TRY_AGAIN_TOMORROW":
6569
msg.reply("La musique du jour a déjà été changée aujourd'hui !")
70+
return
6671

6772
self.bot.log.info("Music of the day changed by " + msg.user)
6873
self.make_topic(msg, new_music=music_url)
69-
try:
70-
title = self.find_title(music_url)
71-
except:
72-
self.bot.log.exception("Fetch MotD title")
73-
title = ""
74+
75+
title = self.find_title(music_url)
76+
title = title if title else music_url
77+
7478
fmt = "tu viens de changer la musique du jour >>> d*-*b <<< {}"
7579
msg.reply(fmt.format(self.bot.text.bold(title)), hilight=True)
7680

requirements.txt

Lines changed: 49 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -4,111 +4,103 @@
44
#
55
# pip-compile
66
#
7-
aioauth-client==0.28.1
7+
aioauth-client==0.29.0
88
# via -r requirements.in
9-
aiohttp==3.8.6
10-
# via -r requirements.in
11-
aiosignal==1.3.1
9+
aiohappyeyeballs==2.6.1
1210
# via aiohttp
13-
anyio==3.6.2
14-
# via httpcore
15-
async-timeout==4.0.2
11+
aiohttp==3.11.15
12+
# via -r requirements.in
13+
aiosignal==1.3.2
1614
# via aiohttp
15+
anyio==4.9.0
16+
# via httpx
1717
asyncio-irc @ git+https://github.com/titouanc/asyncirc
1818
# via -r requirements.in
19-
attrs==22.2.0
19+
attrs==25.3.0
2020
# via aiohttp
21-
beautifulsoup4==4.12.2
21+
beautifulsoup4==4.13.3
2222
# via -r requirements.in
23-
blinker==1.5
23+
blinker==1.9.0
2424
# via asyncio-irc
25-
brotli==1.0.9
26-
# via yt-dlp
27-
build==0.9.0
25+
build==1.2.2.post1
2826
# via pip-tools
29-
certifi==2022.12.7
27+
certifi==2025.1.31
3028
# via
3129
# httpcore
3230
# httpx
3331
# sentry-sdk
34-
# yt-dlp
35-
charset-normalizer==2.1.1
36-
# via aiohttp
37-
click==8.1.3
32+
click==8.1.8
3833
# via pip-tools
39-
frozenlist==1.3.3
34+
frozenlist==1.5.0
4035
# via
4136
# aiohttp
4237
# aiosignal
4338
h11==0.14.0
4439
# via httpcore
45-
httpcore==0.16.3
40+
httpcore==1.0.7
4641
# via httpx
47-
httpx==0.23.2
42+
httpx==0.28.1
4843
# via aioauth-client
49-
humanize==4.6.0
44+
humanize==4.12.2
5045
# via -r requirements.in
51-
idna==3.4
46+
idna==3.10
5247
# via
5348
# anyio
54-
# rfc3986
49+
# httpx
5550
# yarl
56-
iniconfig==2.0.0
51+
iniconfig==2.1.0
5752
# via pytest
58-
multidict==6.0.4
53+
multidict==6.3.0
5954
# via
6055
# aiohttp
6156
# yarl
62-
mutagen==1.46.0
63-
# via yt-dlp
64-
packaging==22.0
57+
packaging==24.2
6558
# via
6659
# build
6760
# pytest
68-
pep517==0.13.0
69-
# via build
70-
pip-tools==6.13.0
61+
pip-tools==7.4.1
7162
# via -r requirements.in
72-
pluggy==1.0.0
63+
pluggy==1.5.0
7364
# via pytest
74-
pycryptodomex==3.19.1
75-
# via yt-dlp
76-
pytest==7.3.2
65+
propcache==0.3.1
66+
# via
67+
# aiohttp
68+
# yarl
69+
pyproject-hooks==1.2.0
70+
# via
71+
# build
72+
# pip-tools
73+
pytest==8.3.5
7774
# via
7875
# -r requirements.in
7976
# pytest-asyncio
80-
pytest-asyncio==0.21.0
77+
pytest-asyncio==0.26.0
8178
# via -r requirements.in
82-
python-dateutil==2.8.2
79+
python-dateutil==2.9.0.post0
8380
# via -r requirements.in
84-
pytz==2023.3
81+
pytz==2025.2
8582
# via -r requirements.in
86-
rfc3986[idna2008]==1.5.0
87-
# via
88-
# httpx
89-
# rfc3986
90-
roman==4.1
83+
roman==5.0
9184
# via -r requirements.in
92-
sentry-sdk==1.28.1
85+
sentry-sdk==2.25.0
9386
# via -r requirements.in
94-
six==1.16.0
87+
six==1.17.0
9588
# via python-dateutil
96-
sniffio==1.3.0
89+
sniffio==1.3.1
90+
# via anyio
91+
soupsieve==2.6
92+
# via beautifulsoup4
93+
typing-extensions==4.13.0
9794
# via
9895
# anyio
99-
# httpcore
100-
# httpx
101-
soupsieve==2.3.2.post1
102-
# via beautifulsoup4
103-
urllib3==1.26.13
96+
# beautifulsoup4
97+
urllib3==2.3.0
10498
# via sentry-sdk
105-
websockets==10.4
106-
# via yt-dlp
107-
wheel==0.40.0
99+
wheel==0.45.1
108100
# via pip-tools
109-
yarl==1.8.2
101+
yarl==1.18.3
110102
# via aiohttp
111-
yt-dlp==2023.10.7
103+
yt-dlp==2025.3.31
112104
# via -r requirements.in
113105

114106
# The following packages are considered to be unsafe in a requirements file:

0 commit comments

Comments
 (0)