Commit 1faac010 authored by Ferdinand Schober's avatar Ferdinand Schober 💬
Browse files

separated commands and game

parent 9d71a2cc
# The default ````
# flake8: noqa
def set_prefs(prefs):
"""This function is called before opening the project"""
# Specify which files and folders to ignore in the project.
# Changes to ignored resources are not added to the history and
# VCSs. Also they are not returned in `Project.get_files()`.
# Note that ``?`` and ``*`` match all characters but slashes.
# '*.pyc': matches 'test.pyc' and 'pkg/test.pyc'
# 'mod*.pyc': matches 'test/mod1.pyc' but not 'mod/1.pyc'
# '.svn': matches 'pkg/.svn' and all of its children
# 'build/*.o': matches 'build/lib.o' but not 'build/sub/lib.o'
# 'build//*.o': matches 'build/lib.o' and 'build/sub/lib.o'
prefs['ignored_resources'] = ['*.pyc', '*~', '.ropeproject',
'.hg', '.svn', '_svn', '.git', '.tox']
# Specifies which files should be considered python files. It is
# useful when you have scripts inside your project. Only files
# ending with ``.py`` are considered to be python files by
# default.
# prefs['python_files'] = ['*.py']
# Custom source folders: By default rope searches the project
# for finding source folders (folders that should be searched
# for finding modules). You can add paths to that list. Note
# that rope guesses project source folders correctly most of the
# time; use this if you have any problems.
# The folders should be relative to project root and use '/' for
# separating folders regardless of the platform rope is running on.
# 'src/my_source_folder' for instance.
# prefs.add('source_folders', 'src')
# You can extend python path for looking up modules
# prefs.add('python_path', '~/python/')
# Should rope save object information or not.
prefs['save_objectdb'] = True
prefs['compress_objectdb'] = False
# If `True`, rope analyzes each module when it is being saved.
prefs['automatic_soa'] = True
# The depth of calls to follow in static object analysis
prefs['soa_followed_calls'] = 0
# If `False` when running modules or unit tests "dynamic object
# analysis" is turned off. This makes them much faster.
prefs['perform_doa'] = True
# Rope can check the validity of its object DB when running.
prefs['validate_objectdb'] = True
# How many undos to hold?
prefs['max_history_items'] = 32
# Shows whether to save history across sessions.
prefs['save_history'] = True
prefs['compress_history'] = False
# Set the number spaces used for indenting. According to
# :PEP:`8`, it is best to use 4 spaces. Since most of rope's
# unit-tests use 4 spaces it is more reliable, too.
prefs['indent_size'] = 4
# Builtin and c-extension modules that are allowed to be imported
# and inspected by rope.
prefs['extension_modules'] = []
# Add all standard c-extensions to extension_modules list.
prefs['import_dynload_stdmods'] = True
# If `True` modules with syntax errors are considered to be empty.
# The default value is `False`; When `False` syntax errors raise
# `rope.base.exceptions.ModuleSyntaxError` exception.
prefs['ignore_syntax_errors'] = False
# If `True`, rope ignores unresolvable imports. Otherwise, they
# appear in the importing namespace.
prefs['ignore_bad_imports'] = False
# If `True`, rope will insert new module imports as
# `from <package> import <module>` by default.
prefs['prefer_module_from_imports'] = False
# If `True`, rope will transform a comma list of imports into
# multiple separate import statements when organizing
# imports.
prefs['split_imports'] = False
# If `True`, rope will remove all top-level import statements and
# reinsert them at the top of the module when making changes.
prefs['pull_imports_to_top'] = True
# If `True`, rope will sort imports alphabetically by module name instead
# of alphabetically by import statement, with from imports after normal
# imports.
prefs['sort_imports_alphabetically'] = False
# Location of implementation of
# rope.base.oi.type_hinting.interfaces.ITypeHintingFactory In general
# case, you don't have to change this value, unless you're an rope expert.
# Change this value to inject you own implementations of interfaces
# listed in module rope.base.oi.type_hinting.providers.interfaces
# For example, you can add you own providers for Django Models, or disable
# the search type-hinting in a class hierarchy, etc.
prefs['type_hinting_factory'] = (
def project_opened(project):
"""This function is called after opening the project"""
# Do whatever you like here!
A Discord server bot for playing Werewolf
\ No newline at end of file
#Werwölfe von Düsterwald
Ein Discord Server Bot für das Spiel "Werwölfe von Düsterwald"
......@@ -3,7 +3,13 @@ import asyncio
from pprint import pprint
from discord.ext import commands
client = commands.Bot(command_prefix='$')
client = commands.Bot(command_prefix='.')
\ No newline at end of file
import discord
from discord.ext import commands
class Werewolf(commands.Cog):
def __init__(self, client):
self.client = client
async def on_ready(self):
self.commands_channel = await self.client.fetch_channel(696105930336632963)
self.info_channel = await self.client.fetch_channel(696130399860162626)
self.lobby = await self.client.fetch_channel(696130304884211733)
self.welcome_channel = await self.client.fetch_channel(696079221684175005)
self.werewolf_channel = await self.client.fetch_channel(696088648365375570)
async def restart_game(self, ctx):
if != self.commands_channel: return
await self.commands_channel.send('restarting game!')
await self.init_game(self.lobby.members)
async def init_game(self, players):
info = f'starting new game with {[ for member in players]}'
await self.commands_channel.send(info) = game(players)
def game(players): return ''
def setup(client):
\ No newline at end of file
import werewolf_roles
import random
async def start(ctx, _players, _channels, _server_roles):
global role, players, channels, server_roles
role = dict(zip(random.sample(_players,len(_players)), werewolf_roles.get_roles()))
players = set(_players)
channels = _channels
server_roles = _server_roles
await ctx.send(f'starting new game with {[member.mention for member in players]}')
await set_night()
def is_alive(player):
return player in players
def get_role(player):
return role[player]
async def check_time_state():
if tasks == {}:
if state == 'day':
await set_night()
await set_day()
async def set_night():
global state, tasks, werewolf_votes
state = 'night'
tasks = { task for task in [tasks for tasks in [role[player]['tasks'] for player in players]]}
werewolf_votes = dict()
await channels['village_channel'].send('Wieder mal wird es dunkel im Düsterwald und das Dorf schläft ein...')
async def set_day():
global state, accusations, votes, tasks
state = 'day'
accusations = set()
votes = dict()
tasks = {'accusation'}
await channels['village_channel'].send('Das Dorf erwacht...\n'
'Die Anklage ist eröffnet!\n'
'Um eine Person anzuklagen schreibe $accuse @name!\n'
'Mit $withdraw @name können Anklagen zurückgezogen werden!\n')
async def accuse(ctx, player):
if 'accusation' in tasks:
if player in players:
if len(accusations) == 3:
await ctx.send(f'Es sind bereits drei Spieler angeklagt!')
await ctx.send(f'Angeklagt: {[m.mention for m in accusations]}')
await ctx.send(f'{player.mention} ist nicht (mehr) im Spiel')
async def withdraw(ctx, player):
if 'accusation' in tasks:
if player not in accusations:
ctx.send(f'{player.mention} ist nicht angeklagt!')
await ctx.send(f'Angeklagt: {[m.mention for m in accusations]}')
async def confirm_accusations(ctx):
if 'accusation' in tasks:
if len(accusations) < 2:
await ctx.send('Es müssen mindestens 2 Personen angeklagt werden!')
await ctx.send('Die Angeklagen wurden bestätig!'
'Votet nun mit $vote @name für einen der Angeklagten!')
async def citizen_vote(ctx, player):
if 'voting' in tasks:
if player in accusations:
global votes
votes[] = player
await ctx.send(f'Abstimmung: { {k.mention: v.mention for (k, v) in votes.items()} }')
if votes.keys() == players:
votes = {player : votes.values().count(player) for player in set(votes.values())}
victim = max(votes, key=votes.get)
await ctx.send('Die Abstimmung ist beendet:'
f'{} wird hingerichtet!')
await ctx.send(f'{player.mention} ist nicht angeklagt!')
async def werewolf_vote(ctx, player):
if 'werewolfs' in tasks:
werewolf_votes[] = player
if werewolf_votes.keys() == { p for p in players if role[p] == werewolf_roles.werwolf }: #all werewolfs have submitted their vote
if len(set(werewolf_votes.values())) == 1: #all votes are equal
global werewolf_victim
werewolf_victim = list(werewolf_votes.values())[0]
await notify_werewolf_vote()
async def see(ctx, player):
if 'seer' in tasks:
if player in players:
await ctx.send(f'{player.mention} gehört zum Team {role[player]["team"]}')
await ctx.send(f'{player.mention} ist nicht (mehr) im Spiel!')
async def heal(ctx, player):
if 'heal' in tasks:
global werewolf_victim
healed = werewolf_victim
werewolf_victim = None
await ctx.send(f'{healed.mention} wurde geheilt!')
async def notify_werewolf_vote():
\ No newline at end of file
......@@ -2,6 +2,14 @@ import discord
from discord.ext import commands
class Util(commands.Cog):
def __init__(self, client):
self.client = client
async def on_ready(self):
await self.client.change_presence(, activity=discord.Game('with 0s and 1s'))
async def on_member_join(self, member):
print(f'{member} has joined a server')
import discord
from discord.ext import commands
import game
class Werewolf(commands.Cog):
def __init__(self, client):
self.client = client
async def log(self, message):
await self.channels['info_channel'].send(message)
async def on_ready(self):
self.channels = {
'welcome_channel': await self.client.fetch_channel(696079221684175005),
'lobby_channel': await self.client.fetch_channel(696130304884211733),
'village_channel': await self.client.fetch_channel(696105930336632963),
'info_channel': await self.client.fetch_channel(696130399860162626),
'werewolf_channel': await self.client.fetch_channel(696323465195683891),
'couple_channel': await self.client.fetch_channel(696323604605960213),
'witch_channel': await self.client.fetch_channel(696776678541623336),
'seer_channel': await self.client.fetch_channel(696776695146872872),
self.server = await self.client.fetch_guild(696079221684175001)
self.server_roles = {
'alive': await self.server.get_role(697048340889731134),
'dead': await self.server.get_role(697048466978897990)
async def on_message(self, message):
await self.client.process_commands(message)
await game.check_time_state()
async def lobby(self, ctx):
await'{[member.mention for member in self.channels["lobby_channel"].members]}')
async def start(self, ctx):
await ctx.message.delete()
if == self.channels['village_channel']:
await game.start(ctx, set(self.channels['lobby_channel'].members), self.channels, self.server_roles)
async def accuse(self, ctx, *, player: discord.Member):
await ctx.message.delete()
if == self.channels['village_channel']:
await game.accuse(ctx, player)
async def withdraw(self, ctx, *, player: discord.Member):
await ctx.message.delete()
if == self.channels['village_channel']:
await game.withdraw(ctx, player)
async def confirm(self, ctx):
await ctx.message.delete()
if == self.channels['village_channel']:
await game.confirm_accusations(ctx)
async def vote(self, ctx, *, player: discord.Member):
await ctx.message.delete()
if == self.channels['village_channel']:
await game.citizen_vote(ctx, player)
elif == self.channels['werewolf_channel']:
await game.werewolf_vote(ctx, player)
async def see(self, ctx, *, player: discord.Member):
await ctx.message.delete()
if == self.channels['seer_channel']:
await game.see(ctx, player)
async def heal(self, ctx, player: discord.Member):
await ctx.message.delete()
if == self.channels['witch_channel']:
await game.heal(ctx, player)
async def alive(self, ctx):
await ctx.send(f'Noch am Leben: {[p.mention for p in game.players]}')
def setup(client):
def get_roles():
return [werwolf, dorfbewohner, seher, hexe, werwolf, jaeger, amor, hure, werwolf, maedchen]
werwolf = {
'name': 'Werwolf',
'team': 'werwölfe',
'tasks': 'werewolfs',
'channel': 'werewolf_channel',
'description': '''Du bist Werwolf!
In der Nacht stimmst du mit den anderen Werwölfen ab, wer umgebracht wird!
Gehe dazu in den Werwolf-Channel und vote:
'$vote @name'
Wenn alle nacheinander für den gleichen Namen gevoted haben ist die Abstimmung vorbei und das Opfer ist bestimmt!
Guten Appetit!'''
dorfbewohner = {
'name': 'Dorfbewohner',
'team': 'dorf',
'channel': None,
'tasks': [],
'description': '''Du bist Dorfbewohner!
Nein, das ist die spannendste Rolle im Spiel, trust me!
Viel Spaß!'''
seher = {
'name': 'Seher',
'team': 'dorf',
'tasks': 'seer',
'channel': 'seer_channel',
'description': '''Du bist Seher!
Jede Nacht wird dir dank deiner wundersamen Fähigkeiten die Rolle eines Spielers offenbart!
Schreibe dazu im Seher-Channel folgenden Befehl:
'$see @name'
Ich verrate dir dann die Rolle des Spielers!'''
hexe = {
'name': 'Hexe',
'team': 'dorf',
'tasks': ['heal', 'poison'],
'channel': 'witch_channel',
'description': '''Du bist Hexe!
Für die Dauer des Spiels besitzt du einen Heiltrank, sowie einen Todestrank, welche du in der Nacht einsetzen kannst (solange du noch lebst!)
Nachdem die Werwölfe ihr Opfer erwählt haben, erfährst du wen es getroffen hat.
Im ganzen Spiel kannst du folgende Befehle einmal ausführen:
- '$heal' um das Opfer der Werwölfe wieder zu heilen.
- '$kill @name' um einen anderen Spieler zu töten.
Wenn du in einer Nacht nichts tun willst benutze '$pass' um nichts zu tun.
Fröhliches hexen!'''
amor = {
'name': 'Amor',
'team': 'dorf',
'channel': 'amor_channel',
'description': '''Du bist Amor!
In der ersten Nacht kannst du zwei Leute mit deinen Liebespfeilen abschießen.
Danach sind sie unsterblich in einander verliebt!
Stirbt einer der beiden gibt es für den anderen keinen Grund mehr zu leben und er wird Selbstmord begehen!
bonne chute amoureuse!
jaeger = {
'name': 'Jäger',
'team': 'dorf',
'channel': None,
'description': '''Du bist Jäger!
Wenn du stirbst nimmst du Rache!
Mit dem Befehl "$kill @name" kannst du eine Person deiner Wahl umbringen.
hure = {
'name': 'Hure',
'team': 'dorf',
'channel': 'whore_channel',
'description': '''Du bist die Hure!
Du kannst jede Nacht bei einer Person deiner Wahl deine schmutzige Arbeit verrichten...
Wirst du umgebracht, passiert nichts - du bist ja nicht zuhause.
Wird allerdings dein Zuhälter umgebracht stirbst du ebenfalls!
Mit dem Befehlt "$sleep @name" wählst du in der Nacht aus, bei wem du dich aufhältst.
maedchen = {
'name': 'Mädchen',
'team': 'dorf',
'channel': 'girl_channel',
'description': '''Du bist das Mädchen!
Im channel "mädchen" kannst du (anonym) belauschen, was die Werwölfe schreiben...'''
if __name__ == '__main__':
for role in get_roles():
print('\n' + '-' * 20 + '\n')
\ 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