Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@re_botcmd(pattern=r"plz dont match this")
def re_foo(self, msg, match):
"""This runs re_foo."""
return 'bar'
@re_botcmd(pattern=r'^regex command with prefix$', prefixed=True)
def regex_command_with_prefix(self, mess, match):
return "Regex command"
@re_botcmd(pattern=r'match_here', matchall=True)
def regex_command_with_matchall(self, mess, matches):
return len(matches)
@re_botcmd(pattern=r'ls\s+bears\s+((?:[\w\+]+(?:\s+)?)+)',
re_cmd_name_help='ls bears [langs]+')
def ls(self, msg, match):
"""
List bears of given languages:
Example: `ls bears python python3`
"""
langs = list(map(lambda x: x.lower(), match.group(1).split()))
bears = client.list.bears.get().json()
bears = [{**{'name': bear}, **content}
for bear, content in bears.items()]
for lang in langs:
selected_bears = [
' | ' + bear['name'] for bear in filter(lambda x: lang in list(
map(lambda y: y.lower(), x['languages'])),
@re_botcmd(pattern=r'ship\s*it',
re_cmd_name_help='ship it',
flags=re.IGNORECASE)
def ship_it(self, msg, match):
"""
Show motivational ship it squirrel images.
"""
return '![ship it!]({})'.format(
self.IMAGES[random.randint(0, len(self.IMAGES) - 1)]
)
@re_botcmd(pattern=r'ghetto\s+(.+)',
re_cmd_name_help='ghetto ',
flags=re.IGNORECASE)
def ghetto(self, msg, match):
"""
Real talk yo
"""
rq = requests.post('http://www.gizoogle.net/textilizer.php',
data={'translatetext': match.group(1)})
translated_text = re.search(
r'<textarea>(.+)</textarea>', rq.text)
if translated_text is not None:
return translated_text.group(1)
else:
return 'Shiznit happens!'
@re_botcmd(pattern=r'^unassign\s+https://(github|gitlab)\.com/([^/]+)/([^/]+)/issues/(\d+)', # Ignore LineLengthBear, PyCodeStyleBear
re_cmd_name_help='unassign ',
flags=re.IGNORECASE)
def unassign_cmd(self, msg, match):
"""Unassign from an issue.""" # Ignore QuotesBear
org = match.group(2)
repo_name = match.group(3)
issue_number = match.group(4)
user = msg.frm.nick
if not user:
yield 'ERROR: The above command cannot be operated without nick.'
return
try:
assert org == self.GH_ORG_NAME or org == self.GL_ORG_NAME
except AssertionError:
@re_botcmd(pattern=r'the\s+rules',
re_cmd_name_help='the rules',
flags=re.IGNORECASE,
template='the_rules.jinja2')
def the_rules(self, msg, args):
"""
Show the bot rules.
"""
return {'rules': True}
@re_botcmd(pattern=r'^(nm)$|^(nevermind)$', flags=re.IGNORECASE)
def nevermind(self, message, match):
"""Doesn't mind"""
return "I'm sorry :("
@re_botcmd(pattern=r'^assign\s+https://(github|gitlab)\.com/([^/]+)/([^/]+/)+issues/(\d+)', # Ignore LineLengthBear, PyCodeStyleBear
re_cmd_name_help='assign ',
flags=re.IGNORECASE)
def assign_cmd(self, msg, match):
"""Assign to GitLab and GitHub issues.""" # Ignore QuotesBear
org = match.group(2)
repo_name = match.group(3)[:-1]
iss_number = match.group(4)
user = msg.frm.nick
if not user:
yield 'ERROR: The above command cannot be operated without nick.'
return
try:
assert org == self.GH_ORG_NAME or org == self.GL_ORG_NAME
except AssertionError: