Add support for +1 @person and fix !points bug
This commit is contained in:
parent
3918151706
commit
cc6bb01600
1 changed files with 23 additions and 15 deletions
38
PlusOne.py
38
PlusOne.py
|
|
@ -43,7 +43,8 @@ class YourBot(yaboli.Bot):
|
||||||
Count +1s awarded to users by other users.
|
Count +1s awarded to users by other users.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
PLUSONE_RE = r"(\+1|:\+1:|:bronze:)"
|
PLUSONE_RE = r"(\+1|:\+1:|:bronze:)\s*(.*)"
|
||||||
|
MENTION_RE = r"((for|to)\s+)?@(\S+)"
|
||||||
|
|
||||||
def __init__(self, db):
|
def __init__(self, db):
|
||||||
super().__init__("PlusOne")
|
super().__init__("PlusOne")
|
||||||
|
|
@ -60,27 +61,34 @@ class YourBot(yaboli.Bot):
|
||||||
)
|
)
|
||||||
self.ping_message = ":bronze!?:"
|
self.ping_message = ":bronze!?:"
|
||||||
|
|
||||||
self.register_callback("points", self.command_points, specific=False)
|
self.register_command("points", self.command_points, specific=False)
|
||||||
|
self.register_trigger(self.PLUSONE_RE, self.trigger_plusone)
|
||||||
|
|
||||||
async def on_connected(self):
|
async def on_connected(self):
|
||||||
await super().on_connected()
|
await super().on_connected()
|
||||||
await self.db.initialize()
|
await self.db.initialize()
|
||||||
|
|
||||||
async def on_send(self, message):
|
async def trigger_plusone(self, message, match):
|
||||||
await super().on_send(message) # This is where yaboli.bot reacts to commands
|
specific = re.match(self.MENTION_RE, match.group(2))
|
||||||
await self.detect_plusone(message)
|
if specific:
|
||||||
|
nick = specific.group(3)
|
||||||
|
await self.db.add_point(nick)
|
||||||
|
await self.room.send(f"Point for @{mention(nick)} registered.", message.mid)
|
||||||
|
elif message.parent:
|
||||||
|
parent_message = await self.room.get_message(message.parent)
|
||||||
|
sender = parent_message.sender.nick
|
||||||
|
await self.db.add_point(sender)
|
||||||
|
await self.room.send("Point registered.", message.mid)
|
||||||
|
else:
|
||||||
|
await self.room.send("You can't +1 nothing...", message.mid)
|
||||||
|
|
||||||
async def detect_plusone(self, message):
|
async def trigger_plusone_mention(self, message, match):
|
||||||
if re.fullmatch(self.PLUSONE_RE, message.content):
|
nick = match.group(2)
|
||||||
if not message.parent:
|
await self.db.add_point(nick)
|
||||||
await self.room.send("You can't +1 nothing...", message.mid)
|
await self.room.send(f"Point for @{mention(nick)} registered.", message.mid)
|
||||||
else:
|
|
||||||
parent_message = await self.room.get_message(message.parent)
|
|
||||||
sender = parent_message.sender.nick
|
|
||||||
await self.db.add_point(sender)
|
|
||||||
await self.room.send("Point registered.", message.mid)
|
|
||||||
|
|
||||||
async def command_points(self, message, args):
|
async def command_points(self, message, argstr):
|
||||||
|
args = self.parse_args(argstr)
|
||||||
if not args:
|
if not args:
|
||||||
points = await self.db.points_of(message.sender.nick)
|
points = await self.db.points_of(message.sender.nick)
|
||||||
await self.room.send(
|
await self.room.send(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue