Commit 216972ef authored by Ferdinand Schober's avatar Ferdinand Schober 💬
Browse files

mayor rewrite

parent 0cb46a3e
# Default ignored files
/workspace.xml
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8 (2)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/werwolf.iml" filepath="$PROJECT_DIR$/.idea/werwolf.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.8 (2)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="PyDocumentationSettings">
<option name="format" value="PLAIN" />
<option name="myDocStringFormat" value="Plain" />
</component>
</module>
\ No newline at end of file
from roles import Role
from asyncio import create_task
from asyncio import Event
liebespaar_id = 696323604605960213
class Amor(Role):
@classmethod
def get_team(cls): return 'Dorfbewohner'
@classmethod
def get_name(cls): return 'Amor'
@classmethod
def get_channel_id(cls): return 697047699006029884
def __init__(self, game, member):
Role.__init__(self, game, member)
self.amor_event = Event()
async def task(self):
if not self.amor_event.is_set():
l = list()
l.append(create_task(self.game.channel.send('Amor erwacht, er verschießt seine Liebespfeile...')))
l.append(create_task(self.channel.send('Schreibe $love @name1 @name2 um deine Liebespfeile zu verschießen und das Liebespaar zu wählen!')))
l.append(create_task(self.amor_event.wait()))
for t in l: await t
l = list()
l.append(create_task(self.channel.send('Volltreffer!')))
l.append(create_task(self.game.channel.send('Die Liebenden werden dem channel "Liebespaar" hinzugefügt,\n'
'Sie verlieben sich sofort und schreiben sie sich romantische Nachrichten...')))
for t in l: await t
async def love(self, p1, p2):
if not self.amor_event.is_set():
if p1 in self.game.players and p2 in self.game.players:
if p1 == p2:
self.game.amor_channel.send('Ein Liebespaar kann nicht aus zweimal der gleichen Person bestehen!')
self.game.couple = { p1, p2 }
l = list()
l.append(create_task(self.game.server.get_channel(liebespaar_id).set_permissions(p1, read_messages=True, send_messages=True)))
l.append(create_task(self.game.server.get_channel(liebespaar_id).set_permissions(p2, read_messages=True, send_messages=True)))
for t in l: await t
await self.game.server.get_channel(liebespaar_id).send(f'Ihr seid ja ein süßes Paar {[m.mention for m in self.game.couple]} <3')
self.amor_event.set()
else:
await self.channel.send('Mindestends einer der Spieler ist nicht am Leben!\n'
'Sende $alive um zu sehen, wer noch lebt.')
\ No newline at end of file
import asyncio
from pprint import pprint
from discord.ext import commands
client = commands.Bot(command_prefix='$')
client.load_extension('utility_commands')
client.load_extension('cog_werewolf')
client.run('Njk2MTEyNTQ1MDgxMDY1NTU0.Xoj_iQ.VXMY9AUo56o_k-QgLSUWtPldhjE')
\ No newline at end of file
from discord.ext import commands
import asyncio
import roles
from discord import Permissions
from discord import Member
from werewolf import Werewolf
from villager import Villager
from seer import Seer
from witch import Witch
from hunter import Hunter
from amor import Amor
from whore import Whore
from girl import Girl
from game import Game
from day import Day
guild_id = 696079221684175001
welcome_channel_id = 696079221684175005
lobby_channel_id = 696130304884211733
class Werwolf(commands.Cog):
def __init__(self, client):
self.client = client
self.init_event = asyncio.Event()
self.game_event = asyncio.Event()
@commands.Cog.listener()
async def on_message(self, message):
await self.init_event.wait()
if message.channel.id == Werewolf.get_channel_id():
await self.server.get_channel(Girl.get_channel_id()).send(message.content)
@commands.Cog.listener()
async def on_ready(self):
self.server = self.client.guilds[0]
self.welcome_channel = self.server.get_channel(welcome_channel_id)
self.lobby_channel = self.server.get_channel(lobby_channel_id)
self.init_event.set()
await self.welcome_channel.send('[status] ready')
@commands.command()
async def start(self, ctx):
await self.init_event.wait()
print(self.game_event.is_set())
if self.game_event.is_set():
await ctx.send('Spiel läuft bereits!')
return
self.game_event.set()
members = self.server.get_channel(lobby_channel_id).members
self.game = Game(self.server, members)
await self.game.play(ctx)
self.game_event.clear()
@commands.command()
async def accuse(self, ctx, *, player:Member):
await self.game.day.accuse(ctx, player)
@commands.command()
async def withdraw(self, ctx, *, player:Member):
await self.game.day.withdraw(ctx, player)
@commands.command()
async def confirm(self, ctx):
await self.game.day.confirm(ctx)
@commands.command()
async def vote(self, ctx, *, player:Member):
if ctx.channel.id == Werewolf.get_channel_id():
await self.game.role[ctx.message.author].vote(ctx, player)
elif ctx.channel.id == Day.get_channel_id():
await self.game.day.vote(ctx, ctx.message.author, player)
@commands.command()
async def captain(self, ctx):
await self.game.day.print_captain(ctx)
@commands.command()
async def heal(self, ctx):
if ctx.channel.id == Witch.get_channel_id():
await self.game.role[ctx.message.author].heal()
@commands.command()
async def poison(self, ctx, *, player:Member):
if ctx.channel.id == Witch.get_channel_id():
self.game.role[ctx.message.author].poison(player)
@commands.command()
async def see(self, ctx, *, player:Member):
if ctx.channel.id == Seer.get_channel_id():
await self.game.role[ctx.message.author].see(player)
@commands.command()
async def kill(self, ctx, *, player:Member):
if ctx.channel.id == Witch.get_channel_id():
await self.game.role[ctx.message.author].poison(player)
if isinstance(self.game.role[ctx.message.author], Hunter):
await self.game.role[ctx.message.author].kill(ctx, player)
@commands.command()
async def love(self, ctx, p1:Member, p2:Member):
if ctx.channel.id == Amor.get_channel_id():
await self.game.role[ctx.message.author].love(p1, p2)
@commands.command()
async def sleep(self, ctx, *, player:Member):
if ctx.channel.id == Whore.get_channel_id():
await self.game.role[ctx.message.author].sleep(player)
@commands.command()
async def tasks(self, ctx):
for task in self.game.night.task_list:
await ctx.send(str(task))
@commands.command()
async def no(self, ctx):
if ctx.channel.id == Witch.get_channel_id():
await self.game.role[ctx.message.author].no()
@commands.command()
async def alive(self, ctx):
await self.game.print_living(ctx)
@commands.command()
async def votes(self, ctx):
await self.game.day.print_votes(ctx)
def setup(client):
client.add_cog(Werwolf(client))
\ No newline at end of file
from asyncio import Event
from asyncio import create_task
import roles
from werewolf import Werewolf
import random
from day import Day
from night import Night
game_category_id = 696079221684175004
village_channel_id = 696105930336632963
role_alive_id = 697048340889731134
role_dead_id = 697048466978897990
class Game():
def __init__(self, server, members):
self.server = server
self.players = set(members)
self.role = roles.distribute_roles(self, members)
self.player = { v: k for k, v in self.role.items() }
self.couple = {}
self.role_alive = self.server.get_role(role_alive_id)
self.role_dead = self.server.get_role(role_dead_id)
self.channel = self.server.get_channel(village_channel_id)
self.day = Day(self)
self.night = Night(self)
async def play(self, ctx):
l = list()
for player in self.players:
l.append(create_task(player.remove_roles(self.role_dead)))
l.append(create_task(player.add_roles(self.role_alive)))
l.append(create_task(self.set_channel_for_member(self.role[player].get_channel_id(), player)))
for channel in self.server.get_channel(game_category_id).text_channels:
l.append(create_task(channel.purge()))
for task in l:
await task
await ctx.send(f'Starte neues Spiel mit { [p.mention for p in self.players] }')
await self.channel.send(f'Es spielen mit: {[role.get_name() for role in self.role.values()]}')
while True:
if await self.night.tasks(): break
if await self.day.tasks(): break
async def check_winconditions(self):
print({ self.role[p].get_team() for p in self.players})
if len(self.players) == 0:
await self.channel.send('Somit ist das Spiel vorbei!\nNiemand hat gewonnen!')
return True
elif self.players == self.couple:
await self.channel.send('Somit ist das Spiel vorbei!\nDas Liebespaar hat gewonnen!')
return True
elif len({ self.role[p].get_team() for p in self.players}) == 1:
await self.channel.send(f'Somit ist das Spiel vorbei!\nDie {self.role[next(iter(self.players))].get_team()} haben gewonnen!')
return True
return False
async def set_channel_for_member(self, channel_id, member):
l = list()
for channel in self.server.get_channel(game_category_id).channels:
l.append(create_task(channel.set_permissions(member, overwrite=None)))
channel = self.server.get_channel(channel_id)
l.append(channel.set_permissions(member, read_messages=True, send_messages=True))
l.append(self.channel.set_permissions(member, send_messages=True))
for t in l:
await t
async def kill(self, player):
self.players.remove(player)
if player in self.couple:
for p in self.couple:
if p in self.players:
await self.channel.send(f'Ohne {player.mention} hat für {p.mention} das Leben keinen Sinn mehr! {p.mention} begeht Selbstmord :(')
self.couple = {}
await self.kill(p)
await self.role[player].on_kill()
l = list()
l.append(create_task(player.add_roles(self.role_dead)))
l.append(create_task(player.remove_roles(self.role_alive)))
for channel in self.server.get_channel(game_category_id).channels:
l.append(create_task(channel.set_permissions(player, read_messages=True, send_messages=False)))
for t in l:
await t
def get_living(self):
return { p for p in self.players if isinstance(self.role[p], self) }
async def print_living(self, ctx):
await ctx.send(f'Es leben noch {[p.mention for p in self.players]}')
\ No newline at end of file
from discord.ext.commands import Bot
from .cogs import utility_commands
from .cogs import werewolf_commands
from .config.server_config import server_config
def run():
client = Bot(command_prefix='$')
client.load_extension('game.cogs.utility_commands')
client.load_extension('game.cogs.werewolf_commands')
client.run(server_config['bot_token'])
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment