-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Redo some common check as a decorator, add a new one, change tests accordingly
- Loading branch information
1 parent
f8a213e
commit 65e81af
Showing
3 changed files
with
115 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from functools import wraps | ||
import asyncio | ||
|
||
|
||
def nickserv_identified(func): | ||
@wraps(func) | ||
async def wrapper(*args, **kwargs): | ||
try: | ||
self, mask = args[0], args[1] | ||
if not (await self._Plugin__is_nick_serv_identified(mask.nick)): | ||
return | ||
except Exception: | ||
pass | ||
return func(*args, **kwargs) | ||
|
||
@wraps(func) | ||
async def async_wrapper(*args, **kwargs): | ||
try: | ||
self, mask = args[0], args[1] | ||
if not (await self._Plugin__is_nick_serv_identified(mask.nick)): | ||
return | ||
except Exception: | ||
pass | ||
return await func(*args, **kwargs) | ||
|
||
if asyncio.iscoroutinefunction(func): | ||
return async_wrapper | ||
else: | ||
return wrapper | ||
|
||
|
||
def channel_only(func): | ||
@wraps(func) | ||
def wrapper(*args, **kwargs): | ||
try: | ||
self, target = args[0], args[2] | ||
if not self._is_a_channel(target): | ||
return 'You can only use this command in channels.' | ||
except Exception: | ||
pass | ||
return func(*args, **kwargs) | ||
|
||
@wraps(func) | ||
async def async_wrapper(*args, **kwargs): | ||
try: | ||
self, target = args[0], args[2] | ||
if not self._is_a_channel(target): | ||
return 'You can only use this command in channels.' | ||
except Exception: | ||
pass | ||
return await func(*args, **kwargs) | ||
|
||
if asyncio.iscoroutinefunction(func): | ||
return async_wrapper | ||
else: | ||
return wrapper |
Oops, something went wrong.