You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Fox-V3/werewolf/votegroups/wolfvote.py

74 lines
2.2 KiB

import logging
7 years ago
import random
import discord
from werewolf.listener import wolflistener
from werewolf.votegroup import VoteGroup
7 years ago
log = logging.getLogger("red.fox_v3.werewolf.votegroup.wolfvote")
7 years ago
class WolfVote(VoteGroup):
"""
Werewolf implementation of base VoteGroup class
"""
7 years ago
alignment = 2 # 1: Town, 2: Werewolf, 3: Neutral
channel_id = "werewolves"
7 years ago
kill_messages = [
7 years ago
"**{ID}** - {target} was mauled by wolves",
"**{ID}** - {target} was found torn to shreds",
]
7 years ago
def __init__(self, game, channel):
7 years ago
super().__init__(game, channel)
self.killer = None # Added killer
@wolflistener("at_night_start", priority=2)
async def _at_night_start(self):
await super()._at_night_start()
7 years ago
7 years ago
mention_list = " ".join(player.mention for player in self.players)
if mention_list != "":
await self.channel.send(mention_list)
self.killer = random.choice(self.players)
7 years ago
await self.channel.send(
f"{self.killer.member.display_name} has been selected as tonight's killer"
)
7 years ago
@wolflistener("at_night_end", priority=5)
async def _at_night_end(self):
7 years ago
if self.channel is None:
return
7 years ago
target_id = None
7 years ago
vote_list = list(self.vote_results.values())
7 years ago
7 years ago
if vote_list:
7 years ago
target_id = max(set(vote_list), key=vote_list.count)
7 years ago
log.debug("Target id: {target_id}\nKiller: {self.killer.member.display_name}")
7 years ago
if target_id is not None and self.killer:
7 years ago
await self.game.kill(target_id, self.killer, random.choice(self.kill_messages))
await self.channel.send(
"**{} has left to complete the kill...**".format(self.killer.member.display_name)
)
7 years ago
else:
await self.channel.send("**No kill will be attempted tonight...**")
7 years ago
7 years ago
async def vote(self, target, author, target_id):
7 years ago
"""
Receive vote from game
"""
7 years ago
await super().vote(target, author, target_id)
7 years ago
await self.channel.send(
"{} has voted to kill {}".format(author.mention, target.member.display_name),
allowed_mentions=discord.AllowedMentions(everyone=False, users=[author])
)