Skip to content
This repository was archived by the owner on Oct 18, 2021. It is now read-only.

Commit 26322e7

Browse files
committed
Update to new gs6ex config system
1 parent c3b1f3b commit 26322e7

File tree

3 files changed

+22
-23
lines changed

3 files changed

+22
-23
lines changed

cheatsh.py

+12-13
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
from ... import module as mod
88

99

10+
log = mod.get_logger()
11+
1012

1113
escape_tt = str.maketrans({
1214
'`': '\\`'
@@ -16,19 +18,20 @@
1618

1719

1820
class CheatShModule(mod.Module):
19-
def on_load(self):
20-
self.conf.setdefault('max_length', 1000)
21-
self.conf.sync()
22-
23-
self.session = None
21+
class Config(mod.Config):
22+
max_length: int = 1000
2423

25-
def on_unload(self):
24+
async def on_load(self):
25+
self.session = aiohttp.ClientSession()
26+
log.info('Session opened')
27+
28+
async def on_unload(self):
2629
if self.session:
27-
self.log.info('Closing session...')
28-
mod.loop.create_task(self.session.close())
30+
log.info('Closing session...')
31+
await self.session.close()
2932

3033
def result_fmt(self, url, language, body_text):
31-
body_space = min(1992 - len(language) - len(url), self.conf['max_length'])
34+
body_space = min(1992 - len(language) - len(url), self.conf.max_length)
3235

3336
if len(body_text) > body_space:
3437
return f'```{language}\n{body_text[:body_space - 20]}\n[...]```\nFull results: {url}'
@@ -39,10 +42,6 @@ def result_fmt(self, url, language, body_text):
3942
async def cmd_csh(self, ctx, language: str, *search_terms: str):
4043
url = f'https://cheat.sh/{quote_plus(language)}/{quote_plus(" ".join(search_terms))}'
4144

42-
if not self.session:
43-
self.session = aiohttp.ClientSession()
44-
self.log.info('Session opened')
45-
4645
async with self.session.get(
4746
url,
4847
headers={'User-Agent': 'curl/7.68.0'},

mdn.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
from ... import module as mod
1010

1111

12+
log = mod.get_logger()
13+
14+
1215
url_tt = str.maketrans({
1316
')': '\\)'
1417
})
@@ -17,20 +20,17 @@
1720

1821

1922
class MDNModule(mod.Module):
20-
def on_load(self):
21-
self.session = None
23+
async def on_load(self):
24+
self.session = aiohttp.ClientSession()
25+
log.info('Session opened')
2226

23-
def on_unload(self):
27+
async def on_unload(self):
2428
if self.session:
25-
self.log.info('Closing session...')
26-
mod.loop.create_task(self.session.close())
29+
log.info('Closing session...')
30+
await self.session.close()
2731

2832
@cmd.command(name='mdn', usage='mdn <search terms>', description='Search the Mozilla Developer Network')
2933
async def cmd_mdn(self, ctx, *search_terms: str):
30-
if not self.session:
31-
self.session = aiohttp.ClientSession()
32-
self.log.info('Session opened')
33-
3434
# TODO: Deal with timeouts ~hmry (2020-01-20, 01:25)
3535
async with self.session.get(
3636
'https://developer.mozilla.org/api/v1/search/en-US',

stuxx.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818

1919
class StuxxModule(mod.Module):
20-
def on_load(self):
20+
async def on_load(self):
2121
self.last_response = None
2222

2323
@mod.Module.listener()

0 commit comments

Comments
 (0)