Skip to content

Commit

Permalink
A lot of uncoordinated stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Eisfunke committed Aug 22, 2020
1 parent 661c458 commit 5194f65
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 54 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# config
config
start

# PyCharm config
.idea
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Secret Hitler: Telegram
# Secret Hitler Bot for Telegram

**A Telegram bot that allows users to play [Secret Hitler](https://www.secrethitler.com/).**

Expand Down Expand Up @@ -26,6 +26,6 @@ To get the bot working, you need to create the folder `config` and place these f

## License and Attribution

Secret Hitler is designed by Max Temkin, Mike Boxleiter, Tommy Maranges and illustrated by Mackenzie Schubert.
[Secret Hitler](https://www.secrethitler.com/) was designed by Max Temkin, Mike Boxleiter, Tommy Maranges and illustrated by Mackenzie Schubert.

The game and therefore this bot as well are licensed as per the [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-nc-sa/4.0/) license.
The game and therefore this bot are licensed as per the [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-nc-sa/4.0/) license.
9 changes: 0 additions & 9 deletions game_peek.py

This file was deleted.

11 changes: 3 additions & 8 deletions bot_telegram.py → src/bot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import logging
import os
Expand All @@ -15,12 +14,7 @@
from telegram.ext import Updater, CommandHandler, CallbackContext, CallbackQueryHandler
from telegram.error import TelegramError


with open("config/key", "r") as file:
API_KEY = file.read().rstrip()

with open("config/devchat", "r") as file:
DEV_CHAT_ID = int(file.read().rstrip())
DEV_CHAT_ID = int(os.environ["SECRET_HITLER_BOT_DEVCHAT"])

updater = Updater(os.environ["SECRET_HITLER_BOT_TOKEN"], use_context=True)
# restored_players = {}
Expand Down Expand Up @@ -80,7 +74,8 @@ def main():
level=logging.INFO) # not sure exactly how this works

updater.start_polling()
updater.bot.send_message(chat_id=DEV_CHAT_ID, text="Bot started successfully!")
# updater.bot.send_message(chat_id=DEV_CHAT_ID, text="Good morning, comrades! \
# The bot has started. Let's crush fascism.\n\nbtw: richard ist ein frechdachs")


def split_message(message, length=MAX_MESSAGE_LENGTH):
Expand Down
File renamed without changes.
59 changes: 27 additions & 32 deletions model.py → src/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

class GameState(enum.Enum):
"""Enum for the different states a game can be in."""

ACCEPT_PLAYERS = 1 # Game has not started yet and is accepting player entries.
CHANCY_NOMINATION = 2 # The president has to nominate a chancellor.
ELECTION = 3 # There is an ongoing election.
Expand Down Expand Up @@ -40,7 +39,7 @@ class Role(enum.Enum):


class Game(Base):
"""Main class. An instance represents a single game of Secret Hitler."""
"""Represents a single game of Secret Hitler."""
__tablename__ = "games"

def __init__(self, chat):
Expand All @@ -50,17 +49,16 @@ def __init__(self, chat):
chat = Column(Integer, primary_key=True)

# The participating players.
players = relationship("Player", foreign_keys="[Player.game_id]",
players = relationship("Player", foreign_keys="[Player.game_chat]",
cascade="all, delete, delete-orphan")

cards = relationship("Card") # Cards on the deck.
cards = relationship("Card", cascade="all, delete, delete-orphan") # Cards on the deck.
discards = relationship("Discard") # Discarded policies.

president_id = Column(Integer, ForeignKey("players.id"))
president = relationship("Player", foreign_keys="[Game.president_id]") # Current president.

president = relationship("Player", foreign_keys="[Player.game_chat]") # Current president.
chancellor_id = Column(Integer, ForeignKey("players.id"))
chancellor = relationship("Player", foreign_keys="[Game.chancellor_id]") # Current chancellor.
chancellor = relationship("Player", foreign_keys="[Player.game_chat]") # Current chancellor.

last_nonspecial_president_id = Column(Integer, ForeignKey("players.id"))
last_nonspecial_president = relationship("Player",
Expand All @@ -70,9 +68,10 @@ def __init__(self, chat):
spectators = relationship("Spectator", cascade="all, delete, delete-orphan")

# time_logs = relationship("TimeLog")
logs = relationship("Log")
# logs = relationship("Log")

votes = relationship("Vote")
votes = relationship("Vote", foreign_keys="[Vote.game_id]",
cascade="all, delete, delete-orphan")

vetoable_policy = Column(Enum(Policy))
president_veto_vote = Column(Boolean)
Expand All @@ -85,9 +84,9 @@ def __init__(self, chat):
state = Column(Enum(GameState), default=GameState.ACCEPT_PLAYERS)


log_player_table = Table("association", Base.metadata,
Column("log", Integer, ForeignKey("logs.id")),
Column("player", Integer, ForeignKey("players.id")))
#log_player_table = Table("association", Base.metadata,
# Column("log", Integer, ForeignKey("logs.id")),
# Column("player", Integer, ForeignKey("players.id")))


class Player(Base):
Expand Down Expand Up @@ -116,7 +115,7 @@ def __str__(self):
confirmed_not_hitler = Column(Boolean)
dead = Column(Boolean)

known_logs = relationship("Log", secondary=log_player_table, back_populates="known_to")
#known_logs = relationship("Log", secondary=log_player_table, back_populates="known_to")


class Spectator(Base):
Expand All @@ -128,13 +127,23 @@ class Spectator(Base):
game = relationship("Game", back_populates="spectators")


class Card(Base):
__tablename__ = "cards"
class Vote(Base):
"""Represents a single vote."""
__tablename__ = "votes"

id = Column(Integer, primary_key=True)

game_chat = Column(Integer, ForeignKey("games.chat"), nullable=False)
game_chat = Column(Integer, ForeignKey("games.chat"))

player_id = Column(Integer, ForeignKey("players.id"), nullable=False)

vote = Column(Boolean, nullable=False)


class Card(Base):
__tablename__ = "cards"
id = Column(Integer, primary_key=True)
game_chat = Column(Integer, ForeignKey("games.chat"), nullable=False)
policy = Column(Enum(Policy))


Expand All @@ -148,7 +157,7 @@ class Discard(Base):
policy = Column(Enum(Policy))


class Log(Base):
"""class Log(Base):
__tablename__ = "logs"
id = Column(Integer, primary_key=True)
Expand All @@ -161,6 +170,7 @@ class Log(Base):
# Only lists players, not spectators, they have to be handled seperately
known_to = relationship("Player", secondary=log_player_table, back_populates="known_logs")
known_to_group = Column(Boolean)
"""

""" TODO Implement time logs
class TimeLog(Base):
Expand All @@ -173,18 +183,3 @@ class TimeLog(Base):
# time_logs : List<Map<GameState, Map<Player,Timestamp>>>
"""


class Vote(Base):
"""Represents a single vote."""
__tablename__ = "votes"

id = Column(Integer, primary_key=True)

game_id = Column(Integer, ForeignKey("games.id"), nullable=False)
game = relationship("Game", back_populates="votes")

player_id = Column(Integer, ForeignKey("players.id"), nullable=False)
player = relationship("Player")

vote = Column(Boolean, nullable=False)
2 changes: 0 additions & 2 deletions player.py → src/player.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

from model import Player


Expand Down

0 comments on commit 5194f65

Please sign in to comment.