1
Fork 0
mirror of https://github.com/RYGhub/royal-mifia.git synced 2024-11-21 13:34:17 +00:00

Added sentry integration and ondeath() method

This commit is contained in:
Steffo 2016-08-09 13:51:56 +02:00
parent 881f426b43
commit 2f97fe7eb0
2 changed files with 67 additions and 24 deletions

2
.gitignore vendored
View file

@ -113,3 +113,5 @@ $RECYCLE.BIN/
.pyc
.idea/*
*.p
.idea/
sentrykey.txt

65
main.py
View file

@ -7,13 +7,50 @@ from telegram import ParseMode
import filemanager
import random
import strings as s
import logging.config
from raven.handlers.logging import SentryHandler
import logging
logger = logging.getLogger()
logger.setLevel(logging.WARN)
sentrykey = filemanager.readfile("sentrykey.txt")
logging.basicConfig(level=logging.WARN,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler = SentryHandler(
sentrykey)
logging.config.dictConfig({
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'console': {
'format': '[%(asctime)s][%(levelname)s] %(name)s '
'%(filename)s:%(funcName)s:%(lineno)d | %(message)s',
'datefmt': '%H:%M:%S',
},
},
'handlers': {
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'console'
},
'sentry': {
'level': 'WARNING',
'class': 'raven.handlers.logging.SentryHandler',
'dsn': sentrykey,
},
},
'loggers': {
'': {
'handlers': ['console', 'sentry'],
'level': 'DEBUG',
'propagate': False,
},
'your_app': {
'level': 'DEBUG',
'propagate': True,
},
}
})
token = filemanager.readfile('telegramapi.txt')
updater = Updater(token)
@ -39,7 +76,11 @@ class Role:
pass
def onendday(self, bot, game):
"""Metodo chiamato alla fine di ogni giorno, per attivare o ripristinare allo stato iniziale il potere."""
"""Metodo chiamato alla fine di ogni giorno."""
pass
def ondeath(self, bot, game):
"""Metodo chiamato alla morte del giocatore."""
pass
@ -89,7 +130,7 @@ class Mifioso(Role):
# Uccidi il bersaglio se non è protetto da un Angelo.
if self.target is not None:
if self.target.protectedby is None:
self.target.kill()
self.target.kill(bot, game)
game.message(bot, s.mifia_target_killed.format(target=self.target.tusername,
icon=self.target.role.icon,
role=self.target.role.name))
@ -201,9 +242,9 @@ class Player:
"""Manda un messaggio privato al giocatore."""
bot.sendMessage(self.tid, text, parse_mode=ParseMode.MARKDOWN)
def kill(self):
def kill(self, bot, game):
"""Uccidi il giocatore."""
# Perchè questo esiste?
self.role.ondeath(bot, game)
self.alive = False
@ -376,7 +417,7 @@ class Game:
self.message(bot, s.player_lynched.format(name=lynched.tusername,
icon=lynched.role.icon,
role=lynched.role.name))
lynched.kill()
lynched.kill(bot, self)
else:
self.message(bot, s.no_players_lynched)
# Fai gli endday in un certo ordine.
@ -393,7 +434,7 @@ class Game:
killed = killlist.pop()
if killed.alive:
if killed.protectedby is None:
killed.kill()
killed.kill(bot, self)
self.message(bot, s.mifia_target_killed.format(target=killed.tusername,
icon=killed.role.icon,
role=killed.role.name))
@ -682,7 +723,7 @@ def kill(bot, update):
if update.message.from_user['id'] == game.adminid:
target = game.findplayerbyusername(update.message.text.split(' ')[1])
if target is not None:
target.kill()
target.kill(bot, game)
game.message(bot, s.admin_killed.format(name=target.tusername,
icon=target.role.icon,
role=target.role.name))