mirror of
https://github.com/myned/modufur.git
synced 2024-11-01 13:02:38 +00:00
Merge branch 'dev'
This commit is contained in:
commit
f3f7533b75
4 changed files with 20 additions and 7 deletions
|
@ -32,6 +32,7 @@ class Bot:
|
|||
# loop = self.bot.loop.all_tasks()
|
||||
# for task in loop:
|
||||
# task.cancel()
|
||||
u.close()
|
||||
await self.bot.logout()
|
||||
await self.bot.close()
|
||||
print('\n/ / / / / / / / / / / /\nD I S C O N N E C T E D\n\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\\n')
|
||||
|
@ -48,6 +49,7 @@ class Bot:
|
|||
# loop = self.bot.loop.all_tasks()
|
||||
# for task in loop:
|
||||
# task.cancel()
|
||||
u.close()
|
||||
await self.bot.logout()
|
||||
await self.bot.close()
|
||||
os.execl(sys.executable, 'python3', 'run.py')
|
||||
|
|
|
@ -41,6 +41,7 @@ async def on_ready():
|
|||
|
||||
@bot.event
|
||||
async def on_error(error):
|
||||
u.close()
|
||||
await bot.logout()
|
||||
await bot.close()
|
||||
print('\n! ! ! ! !\nE R R O R : {}\n! ! ! ! !\n'.format(error), file=sys.stderr)
|
||||
|
|
|
@ -6,10 +6,10 @@ from utils import utils as u
|
|||
|
||||
|
||||
async def check_match(url):
|
||||
r = await u.fetch('http://iqdb.harry.lu/?url={}'.format(url))
|
||||
content = await u.fetch('http://iqdb.harry.lu', params={'url': url})
|
||||
|
||||
try:
|
||||
value = BeautifulSoup(await r.read(), 'html.parser').find_all('a')[1].get('href')
|
||||
value = BeautifulSoup(content, 'html.parser').find_all('a')[1].get('href')
|
||||
except IndexError:
|
||||
raise exc.MatchError
|
||||
|
||||
|
|
|
@ -68,10 +68,20 @@ async def clear(obj, interval=10 * 60, replace=None):
|
|||
obj = replace
|
||||
asyncio.sleep(interval)
|
||||
|
||||
session = aiohttp.ClientSession()
|
||||
|
||||
|
||||
def close():
|
||||
global session
|
||||
|
||||
if session:
|
||||
session.close()
|
||||
|
||||
|
||||
async def fetch(url, *, params={}, json=False):
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.get(url, params=params, headers={'user-agent': 'Modumind/0.0.1 (Myned)'}) as r:
|
||||
if json is True:
|
||||
return await r.json()
|
||||
return r
|
||||
global session
|
||||
|
||||
async with session.get(url, params=params, headers={'user-agent': 'Modumind/0.0.1 (Myned)'}) as r:
|
||||
if json is True:
|
||||
return await r.json()
|
||||
return await r.read()
|
||||
|
|
Loading…
Reference in a new issue