1
Fork 0
mirror of https://github.com/RYGhub/royal-mifia.git synced 2024-11-21 21:34:20 +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 .pyc
.idea/* .idea/*
*.p *.p
.idea/
sentrykey.txt

65
main.py
View file

@ -7,13 +7,50 @@ from telegram import ParseMode
import filemanager import filemanager
import random import random
import strings as s import strings as s
import logging.config
from raven.handlers.logging import SentryHandler
import logging sentrykey = filemanager.readfile("sentrykey.txt")
logger = logging.getLogger()
logger.setLevel(logging.WARN)
logging.basicConfig(level=logging.WARN, handler = SentryHandler(
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') 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') token = filemanager.readfile('telegramapi.txt')
updater = Updater(token) updater = Updater(token)
@ -39,7 +76,11 @@ class Role:
pass pass
def onendday(self, bot, game): 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 pass
@ -89,7 +130,7 @@ class Mifioso(Role):
# Uccidi il bersaglio se non è protetto da un Angelo. # Uccidi il bersaglio se non è protetto da un Angelo.
if self.target is not None: if self.target is not None:
if self.target.protectedby is 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, game.message(bot, s.mifia_target_killed.format(target=self.target.tusername,
icon=self.target.role.icon, icon=self.target.role.icon,
role=self.target.role.name)) role=self.target.role.name))
@ -201,9 +242,9 @@ class Player:
"""Manda un messaggio privato al giocatore.""" """Manda un messaggio privato al giocatore."""
bot.sendMessage(self.tid, text, parse_mode=ParseMode.MARKDOWN) bot.sendMessage(self.tid, text, parse_mode=ParseMode.MARKDOWN)
def kill(self): def kill(self, bot, game):
"""Uccidi il giocatore.""" """Uccidi il giocatore."""
# Perchè questo esiste? self.role.ondeath(bot, game)
self.alive = False self.alive = False
@ -376,7 +417,7 @@ class Game:
self.message(bot, s.player_lynched.format(name=lynched.tusername, self.message(bot, s.player_lynched.format(name=lynched.tusername,
icon=lynched.role.icon, icon=lynched.role.icon,
role=lynched.role.name)) role=lynched.role.name))
lynched.kill() lynched.kill(bot, self)
else: else:
self.message(bot, s.no_players_lynched) self.message(bot, s.no_players_lynched)
# Fai gli endday in un certo ordine. # Fai gli endday in un certo ordine.
@ -393,7 +434,7 @@ class Game:
killed = killlist.pop() killed = killlist.pop()
if killed.alive: if killed.alive:
if killed.protectedby is None: if killed.protectedby is None:
killed.kill() killed.kill(bot, self)
self.message(bot, s.mifia_target_killed.format(target=killed.tusername, self.message(bot, s.mifia_target_killed.format(target=killed.tusername,
icon=killed.role.icon, icon=killed.role.icon,
role=killed.role.name)) role=killed.role.name))
@ -682,7 +723,7 @@ def kill(bot, update):
if update.message.from_user['id'] == game.adminid: if update.message.from_user['id'] == game.adminid:
target = game.findplayerbyusername(update.message.text.split(' ')[1]) target = game.findplayerbyusername(update.message.text.split(' ')[1])
if target is not None: if target is not None:
target.kill() target.kill(bot, game)
game.message(bot, s.admin_killed.format(name=target.tusername, game.message(bot, s.admin_killed.format(name=target.tusername,
icon=target.role.icon, icon=target.role.icon,
role=target.role.name)) role=target.role.name))