Verified Commit d5ec70fa authored by MAGIC's avatar MAGIC

initial commit

parents
# ignore everything in the `unobot-data` folder
unobot-data/*
# … but don’t ignore the `unobot-data/modules` folder
!unobot-data/modules/
# … but ignore everything inside that `unobot-data/modules` folder
unobot-data/modules/*
# … but don’t ignore the `unobot-data/modules/used` folder
!unobot-data/modules/used/
# … but ignore everything inside that `unobot-data/modules/used` folder
unobot-data/modules/used/*
# … except the `unobot.py` there
!unobot-data/modules/used/unobot.py
# ignore everything in the `mysql-data` folder
mysql-data/*
# … except the `.keep` there
!mysql-data/.keep
# ignore everything in the `znc-data` folder
znc-data/*
# … but don’t ignore the `znc-data/modules` folder
!znc-data/modules/
# … but ignore everything inside that `znc-data/modules` folder
znc-data/modules/*
# … except the `*.cpp` there
!mysql-data/modules/*.cpp
\ No newline at end of file
[submodule "znc-data/modules"]
path = znc-data/modules
url = https://github.com/ChasedSpade/znc-modules.git
branch = master
FROM alpine:3.7
RUN set -x \
&& apk add --no-cache python \
py-mysqldb \
python-dev \
mysql-dev \
\ No newline at end of file
FROM alpine:3.7
# modperl and modpython are built, but won't be loadable.
# :full image installs perl and python3 again, making these modules loadable.
# musl silently doesn't support AI_ADDRCONFIG yet, and ZNC doesn't support Happy Eyeballs yet.
# Together they cause very slow connection. So for now IPv6 is disabled here.
ARG CONFIGUREFLAGS="--prefix=/opt/znc --enable-cyrus --enable-perl --enable-python --disable-ipv6"
ARG MAKEFLAGS=""
ENV ZNC_VERSION git-2017-12-23
RUN set -x \
&& adduser -S znc \
&& addgroup -S znc \
&& apk add --no-cache --virtual runtime-dependencies \
ca-certificates \
cyrus-sasl \
icu \
su-exec \
tini \
tzdata \
&& apk add --no-cache --virtual build-dependencies \
build-base \
curl \
cyrus-sasl-dev \
gnupg \
icu-dev \
libressl-dev \
perl-dev \
python3-dev \
&& mkdir /znc-src && cd /znc-src \
&& curl -fsSL "https://znc.in/nightly/znc-${ZNC_VERSION}.tar.gz" -o znc.tgz \
&& tar -zxf znc.tgz --strip-components=1 \
&& mkdir build && cd build \
&& ../configure ${CONFIGUREFLAGS} \
&& make $MAKEFLAGS \
&& make install \
&& apk del build-dependencies \
&& cd / && rm -rf /znc-src
RUN set -x \
&& apk add --no-cache \
build-base \
icu-dev \
libressl-dev \
perl \
python3
COPY znc-build/entrypoint.sh /
COPY znc-build/00-try-sh.sh /startup-sequence/
COPY znc-build/01-options.sh /startup-sequence/
COPY znc-build/30-build-modules.sh /startup-sequence/
COPY znc-build/50-chown.sh /startup-sequence/
COPY znc-build/99-launch.sh /startup-sequence/
VOLUME /znc-data
ENTRYPOINT ["/entrypoint.sh"]
-- phpMyAdmin SQL Dump
-- version 4.7.7
-- https://www.phpmyadmin.net/
--
-- Host: unobot-db
-- Generation Time: Jan 01, 2018 at 10:13 PM
-- Server version: 10.2.11-MariaDB-10.2.11+maria~jessie
-- PHP Version: 7.1.9
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `unobot`
--
-- --------------------------------------------------------
--
-- Table structure for table `GAME`
--
CREATE TABLE `GAME` (
`WINNER` varchar(200) NOT NULL,
`DURATION` int(11) NOT NULL,
`ID` int(11) NOT NULL,
`SCORE` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- Table structure for table `PLAYERS`
--
CREATE TABLE `PLAYERS` (
`NAME` varchar(200) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- Table structure for table `RELATION`
--
CREATE TABLE `RELATION` (
`PLAYER` varchar(200) NOT NULL,
`DURATION` int(11) NOT NULL,
`ID` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Indexes for dumped tables
--
--
-- Indexes for table `GAME`
--
ALTER TABLE `GAME`
ADD PRIMARY KEY (`DURATION`,`ID`),
ADD UNIQUE KEY `ID` (`ID`);
--
-- Indexes for table `PLAYERS`
--
ALTER TABLE `PLAYERS`
ADD PRIMARY KEY (`NAME`);
--
-- Indexes for table `RELATION`
--
ALTER TABLE `RELATION`
ADD PRIMARY KEY (`PLAYER`,`DURATION`,`ID`);
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
version: '3.3'
services:
znc:
build:
context: .
dockerfile: Dockerfile.ZNC
restart: always
volumes:
- ./znc-data:/znc-data
ports:
- 8000:8000
unobot:
build:
context: .
dockerfile: Dockerfile.UNOBot
volumes:
- ./unobot-data:/root
working_dir: /root
command: ./jenni
restart: always
phpmyadmin:
image: phpmyadmin/phpmyadmin
restart: always
links:
- database:database
environment:
- PMA_HOST=database
ports:
- 8888:80
database:
image: mariadb:10
restart: always
volumes:
- ./mysql-data:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=
- MYSQL_DATABASE=unobot
- MYSQL_USER=unobot
- MYSQL_PASSWORD=
import random
from datetime import datetime, timedelta
import time
import MySQLdb
random.seed()
away_last = 0
BADMIN_CHAN = "#channel" # Must be lowercase
INACTIVE_TIMEOUT = 3
### DATABASE SETTINGS
DB_PASSWORD = ""
DB_HOST = "database"
DB_USER = "unobot"
DB_NAME = "unobot"
STRINGS = {
'ALREADY_STARTED': '\x0FGame already started by \x02%s\x02! Type ".ujoin" to join!',
'GAME_STARTED': '\x0FIRC-UNO started by \x02%s\x02 - Type ".ujoin" to join!',
'GAME_STOPPED': '\x0FGame stopped.',
'CANT_STOP': '\x0F\x02%s\x02 is the game owner, you can\'t stop it! To force stop the game, please wait \x02%s seconds\x02!',
'DEALING_IN': '\x0FDealing \x02%s\x02 into the game as player \x02#%s\x02!',
'JOINED': '\x0FDealing \x02%s\x02 into the game as player \x02#%s\x02!',
'ENOUGH': '\x0FThere are enough players, type \x02.deal\x02 to start!',
'NOT_STARTED': '\x0FGame not started, type \x02.uno\x02 to start!',
'NOT_ENOUGH': '\x0FNot enough players to deal yet.',
'NEEDS_TO_DEAL': '\x0F\x02%s\x02 needs to deal.',
'ALREADY_DEALT': '\x0FAlready dealt.',
'ON_TURN': '\x0FIt\'s \x02%s\'s\x02 turn.',
'DONT_HAVE': '\x0FYou don\'t have that card or it doesn\'t play, \x02%s\x02!',
'DOESNT_PLAY': '\x0FYou don\'t have that card or it doesn\'t play, \x02%s\x02!',
'UNO': '\x0F\x0304UNO! \x02%s\x02 has ONE card left!\x03',
'WIN': '\x0FWe have a winner! \x02%s\x02 beats \x02%d\x02 player(s) in a game that took \x02%s\x02 seconds!',
'DRAWN_ALREADY': '\x0FYou\'ve already drawn, either \x02.pass\x02 or \x02.play\x02!',
'DRAWS': '\x0F\x02%s\x02 draws a card',
'DRAWN_CARD': '\x0FDrawn card: \x02%s\x02',
'DRAW_FIRST': '\x0F\x02%s\x02, you need to draw first!',
'PASSED': '\x0F\x02%s\x02 passed!',
'NO_SCORES': '\x0FNo scores yet',
'TOP_CARD': '\x0F\x02%s\'s\x02 turn. Top Card: \x02%s\x02',
'YOUR_CARDS': '\x0FYour cards: \x02%s\x02',
'NEXT_START': '\x0FNext: ',
'NEXT_PLAYER': '\x0F\x02%s\x02 (\x02%s\x02 cards)',
'D2': '\x0F\x02%s\x02 draws two and is skipped!',
'CARDS': '\x0FCards: \x02%s\x02',
'WD4': '\x0F\x02%s\x02 draws four and is skipped!',
'SKIPPED': '\x0F\x02%s\x02 is skipped!',
'REVERSED': '\x0FOrder reversed!',
'GAINS': '\x0F\x02%s\x02 gains %s points!',
'SCORE_ROW': '\x0F%s: \x02#%s %s\x02 (\x02%s\x02 points, \x02%s\x02 games, \x02%s\x02 won, \x02%.2f\x02 points per game, \x02%.2f\x02 percent wins)',
'GAME_ALREADY_DEALT': 'Game has already been dealt, please wait until game is over or stopped.',
'PLAYER_COLOR_ENABLED': '\x0FHand card colors \x02\x0309enabled\x03\x02! Format: <COLOR>/[<CARD>]. Example: R/[D2] is a red Draw Two.',
'PLAYER_COLOR_DISABLED': '\x0FHand card colors \x02\x0304disabled\x03\x02!',
'DISABLED_PCE': '\x0FHand card colors are \x02\x0304disabled\x03\x02 for \x02%s\x02. To enable, \x02.pce-on\x02',
'ENABLED_PCE': '\x0FHand card colors are \x02\x0309enabled\x03\x02 for \x02%s\x02. To disable, \x02.pce-off\x02',
'PCE_CLEARED': '\x0FAll players\' hand card colors settings are reset by \x02%s\x02.',
'PLAYER_LEAVES': '\x0FPlayer \x02%s\x02 has left the game.',
'OWNER_CHANGE': '\x0FOwner \x02%s\x02 has left the game. New owner is \x02%s\x02.',
}
# List of all Uno thread (or game). One for each channel (Not sure, could be one for each player(?))
unos = {}
# If an update is imminent (it's used to update the game when no one is playing)
update_imminent = False
# Notify the Admin (or the bot's owner) about all games has ended and update is possible
def onGameEnd(jenni):
if update_imminent:
for uno in unos.values():
if not uno.dealt:
jenni.msg(BADMIN_CHAN, "\x02\x0304Nick, all games have finished. You may now update.")
class UnoBot:
def __init__(self, channel):
# Name of the current channel
self.CHANNEL = channel
# Coloured cards number
self.colored_card_nums = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'R', 'S', 'D2']
# Special scores of cards
self.special_scores = {'R' : 20, 'S' : 20, 'D2' : 20, 'W' : 50, 'WD4' : 50}
# Colours name
self.colors = 'RGBY'
# Special cards name
self.special_cards = ['W', 'WD4']
# Players name (Dictionary)
self.players = dict()
# Owners name (Dictionary) TODO what is this?
self.owners = dict()
self.players_pce = dict() # Player color enabled hash table
# Players orders in the game
self.playerOrder = list()
# If game is started (Then it becomes owner (?))
self.game_on = False
# Number of the current player (it's used to extract the player's info on their turn)
self.currentPlayer = 0
# Current top card
self.topCard = None
# Probably the order in witch is played but i'm not sure TODO understan what is this
self.way = 1
# If the current player has drawn i guess (TODO?)
self.drawn = False
# List of the current deck of cards
self.deck = list()
#Probably the current scores (TODO descover this)
self.prescores = list()
# If the owner has dealt
self.dealt = False
# Current time for duration(?) TODO understand what is this
self.lastActive = datetime.now()
# Whatever this is it's (minutes = 3) [TODO check what is timedelta]
self.timeout = timedelta(minutes=INACTIVE_TIMEOUT)
def start(self, jenni, owner):
owner = owner
if self.game_on:
jenni.msg(self.CHANNEL, STRINGS['ALREADY_STARTED'] % self.game_on)
else:
self.lastActive = datetime.now()
self.dealt = False
self.game_on = owner
self.deck = list()
jenni.msg(self.CHANNEL, STRINGS['GAME_STARTED'] % owner)
self.players = dict()
self.players[owner] = list()
self.playerOrder = [owner]
if self.players_pce.get(owner, 0):
self.noticeUser(jenni, owner, STRINGS['ENABLED_PCE'] % owner)
def stop(self, jenni, input):
nickk = (input.nick)
tmptime = datetime.now()
if nickk == self.game_on or tmptime - self.lastActive > self.timeout:
jenni.msg(self.CHANNEL, STRINGS['GAME_STOPPED'])
self.game_on = False
self.dealt = False
onGameEnd(jenni)
elif self.game_on:
jenni.msg(self.CHANNEL, STRINGS['CANT_STOP'] % (self.game_on, self.timeout.seconds - (tmptime - self.lastActive).seconds))
def join(self, jenni, input):
#print dir(jenni.bot)
#print dir(input)
nickk = (input.nick)
if self.game_on:
if not self.dealt:
if nickk not in self.players:
self.players[nickk] = list()
self.playerOrder.append(nickk)
self.lastActive = datetime.now()
if self.players_pce.get(nickk, 0):
self.noticeUser(jenni, nickk, STRINGS['ENABLED_PCE'] % nickk)
if self.deck:
for i in xrange(0, 7):
self.players[nickk].append(self.getCard())
jenni.msg(self.CHANNEL, STRINGS['DEALING_IN'] % (nickk, self.playerOrder.index(nickk) + 1))
else:
jenni.msg(self.CHANNEL, STRINGS['JOINED'] % (nickk, self.playerOrder.index(nickk) + 1))
if len (self.players) == 2:
jenni.msg(self.CHANNEL, STRINGS['ENOUGH'])
else:
jenni.msg(self.CHANNEL, STRINGS['GAME_ALREADY_DEALT'])
else:
jenni.msg(self.CHANNEL, STRINGS['NOT_STARTED'])
def deal(self, jenni, input):
nickk = (input.nick)
if not self.game_on:
jenni.msg(self.CHANNEL, STRINGS['NOT_STARTED'])
return
if len(self.players) < 2:
jenni.msg(self.CHANNEL, STRINGS['NOT_ENOUGH'])
return
if nickk != self.game_on:
jenni.msg(self.CHANNEL, STRINGS['NEEDS_TO_DEAL'] % self.game_on)
return
if len(self.deck):
jenni.msg(self.CHANNEL, STRINGS['ALREADY_DEALT'])
return
self.startTime = datetime.now()
self.lastActive = datetime.now()
self.deck = self.createnewdeck()
for i in xrange(0, 7):
for p in self.players:
self.players[p].append(self.getCard ())
self.topCard = self.getCard()
while self.topCard.lstrip(self.colors) in 'R S D2 W WD4':
self.topCard = self.getCard()
self.currentPlayer = 1
self.cardPlayed(jenni, self.topCard)
self.showOnTurn(jenni)
self.dealt = True
def play(self, jenni, input):
nickk = (input.nick)
if not self.game_on or not self.deck:
return
if nickk != self.playerOrder[self.currentPlayer]:
jenni.msg(self.CHANNEL, STRINGS['ON_TURN'] % self.playerOrder[self.currentPlayer])
return
tok = [z.strip() for z in str(input).upper().split(' ')]
if len(tok) != 3:
return
searchcard = str()
if tok[1] in self.special_cards and tok[2] in self.colors:
searchcard = tok[1]
elif tok[1] in self.colors:
searchcard = (tok[1] + tok[2])
else:
jenni.msg(self.CHANNEL, STRINGS['DOESNT_PLAY'] % self.playerOrder[self.currentPlayer])
return
if searchcard not in self.players[self.playerOrder[self.currentPlayer]]:
jenni.msg(self.CHANNEL, STRINGS['DONT_HAVE'] % self.playerOrder[self.currentPlayer])
return
playcard = (tok[1] + tok[2])
if not self.cardPlayable(playcard):
jenni.msg(self.CHANNEL, STRINGS['DOESNT_PLAY'] % self.playerOrder[self.currentPlayer])
return
self.drawn = False
self.players[self.playerOrder[self.currentPlayer]].remove(searchcard)
pl = self.currentPlayer
self.incPlayer()
self.cardPlayed(jenni, playcard)
if len(self.players[self.playerOrder[pl]]) == 1:
jenni.msg(self.CHANNEL, STRINGS['UNO'] % self.playerOrder[pl])
elif len(self.players[self.playerOrder[pl]]) == 0:
jenni.msg(self.CHANNEL, STRINGS['WIN'] % (self.playerOrder[pl], (len(self.players) - 1), (datetime.now() - self.startTime)))
self.gameEnded(jenni, self.playerOrder[pl])
return
self.lastActive = datetime.now()
self.showOnTurn(jenni)
def draw(self, jenni, input):
nickk = (input.nick)
if not self.game_on or not self.deck:
return
if nickk != self.playerOrder[self.currentPlayer]:
jenni.msg(self.CHANNEL, STRINGS['ON_TURN'] % self.playerOrder[self.currentPlayer])
return
if self.drawn:
jenni.msg(self.CHANNEL, STRINGS['DRAWN_ALREADY'])
return
self.drawn = True
jenni.msg(self.CHANNEL, STRINGS['DRAWS'] % self.playerOrder[self.currentPlayer])
c = self.getCard()
self.players[self.playerOrder[self.currentPlayer]].append(c)
self.lastActive = datetime.now()
self.noticeUser(jenni, nickk, STRINGS['DRAWN_CARD'] % self.renderCards (nickk, [c], 0))
# this is not a typo, avoiding collision with Python's pass keyword
def passs(self, jenni, input):
nickk = (input.nick)
if not self.game_on or not self.deck:
return
if nickk != self.playerOrder[self.currentPlayer]:
jenni.msg(self.CHANNEL, STRINGS['ON_TURN'] % self.playerOrder[self.currentPlayer])
return
if not self.drawn:
jenni.msg(self.CHANNEL, STRINGS['DRAW_FIRST'] % self.playerOrder[self.currentPlayer])
return
self.drawn = False
jenni.msg(self.CHANNEL, STRINGS['PASSED'] % self.playerOrder[self.currentPlayer])
self.incPlayer()
self.lastActive = datetime.now()
self.showOnTurn(jenni)
#TODO remove this method for the MySQL one
def top10(self, jenni, input):
db = MySQLdb.connect(host=DB_HOST, user=DB_USER, passwd=DB_PASSWORD, db=DB_NAME)
nickk = (input.nick)
lines = (format(getAllScoreForBestN(db, 10)))
for line in lines:
jenni.msg(nickk, str(line))
db.close()
def createnewdeck(self):
ret = list()
for i in range(2):
for a in self.colored_card_nums:
for b in self.colors:
if i > 0 and a == '0':
continue
ret.append(b + a)
for a in self.special_cards:
for i in range(4):
ret.append(a)
if len(self.playerOrder) > 4:
ret *= 2
random.shuffle(ret)
return ret
def getCard(self):
ret = self.deck[0]
self.deck.pop(0)
if not self.deck:
self.deck = self.createnewdeck()
return ret
def showOnTurn(self, jenni):
jenni.msg(self.CHANNEL, STRINGS['TOP_CARD'] % (self.playerOrder[self.currentPlayer], self.renderCards(None, [self.topCard], 1)))
self.noticeUser(jenni, self.playerOrder[self.currentPlayer], STRINGS['YOUR_CARDS'] % self.renderCards(self.playerOrder[self.currentPlayer], self.players[self.playerOrder[self.currentPlayer]], 0))
msg = STRINGS['NEXT_START']
tmp = self.currentPlayer + self.way
if tmp == len(self.players):
tmp = 0
if tmp < 0:
tmp = len(self.players) - 1
arr = list()
while tmp != self.currentPlayer:
arr.append(STRINGS['NEXT_PLAYER'] % (self.playerOrder[tmp], len(self.players[self.playerOrder[tmp]])))
tmp = tmp + self.way
if tmp == len(self.players):
tmp = 0
if tmp < 0:
tmp = len(self.players) - 1
msg += ' - '.join(arr)
self.noticeUser(jenni, self.playerOrder[self.currentPlayer], msg)
def showCards(self, jenni, user):
user = user
if not self.game_on or not self.deck:
return
msg = STRINGS['NEXT_START']
tmp = self.currentPlayer + self.way
if tmp == len(self.players):
tmp = 0
if tmp < 0:
tmp = len(self.players) - 1
arr = list()
k = len(self.players)
while k > 0:
arr.append(STRINGS['NEXT_PLAYER'] % (self.playerOrder[tmp], len(self.players[self.playerOrder[tmp]])))
tmp = tmp + self.way
if tmp == len(self.players):
tmp = 0
if tmp < 0:
tmp = len(self.players) - 1
k-=1
msg += ' - '.join(arr)
if user not in self.players:
self.noticeUser(jenni, user, msg)
else:
self.noticeUser(jenni, user, STRINGS['YOUR_CARDS'] % self.renderCards(user, self.players[user], 0))
self.noticeUser(jenni, user, msg)
def renderCards(self, nick, cards, is_chan):
nickk = nick
if nick:
nickk = (nick)
ret = list()
for c in sorted(cards):
if c in ['W', 'WD4']:
sp = str()
if not is_chan and self.players_pce.get(nickk, 0):
sp = ' '
ret.append('[' + c + ']' + sp)
continue
if c[0] == 'W':
c = c[-1] + '*'
t = '\x03\x03'
if c[0] == 'B':
t += '12'
elif c[0] == 'Y':
t += '08'
elif c[0] == 'G':
t += '09'
elif c[0] == 'R':
t += '04'
if not is_chan:
if self.players_pce.get(nickk, 0):
t += '%s/ [%s] ' % (c[0], c[1:])
else:
t += '[%s]' % c[1:]
else:
t += '(%s) [%s]' % (c[0], c[1:])
t += "\x03\x03"
ret.append(t)
return ''.join(ret)
def cardPlayable(self, card):
if card[0] == 'W' and card[-1] in self.colors:
return True
if self.topCard[0] == 'W':
return card[0] == self.topCard[-1]
return (card[0] == self.topCard[0]) or (card[1] == self.topCard[1])
def cardPlayed(self, jenni, card):
if card[1:] == 'D2':
jenni.msg(self.CHANNEL, STRINGS['D2'] % self.playerOrder[self.currentPlayer])
z = [self.getCard(), self.getCard()]
self.noticeUser(jenni, self.playerOrder[self.currentPlayer], STRINGS['CARDS'] % self.renderCards(self.playerOrder[self.currentPlayer], z, 0))
self.players[self.playerOrder[self.currentPlayer]].extend (z)
self.incPlayer()
elif card[:2] == 'WD':
jenni.msg(self.CHANNEL, STRINGS['WD4'] % self.playerOrder[self.currentPlayer])
z = [self.getCard(), self.getCard(), self.getCard(), self.getCard()]
self.noticeUser(jenni, self.playerOrder[self.currentPlayer], STRINGS['CARDS'] % self.renderCards(self.playerOrder[self.currentPlayer], z, 0))
self.players[self.playerOrder[self.currentPlayer]].extend(z)
self.incPlayer()
elif card[1] == 'S':
jenni.msg(self.CHANNEL, STRINGS['SKIPPED'] % self.playerOrder[self.currentPlayer])
self.incPlayer()
elif card[1] == 'R' and card[0] != 'W':
jenni.msg(self.CHANNEL, STRINGS['REVERSED'])
if len(self.players) > 2:
self.way = -self.way
self.incPlayer()
self.incPlayer()
else:
self.incPlayer()
self.topCard = card
def gameEnded(self, jenni, winner):
try:
score = 0
for p in self.players:
for c in self.players[p]:
if c[0] == 'W':
score += self.special_scores[c]
elif c[1] in [ 'S', 'R', 'D' ]:
score += self.special_scores[c[1:]]
else:
score += int(c[1])
jenni.msg(self.CHANNEL, STRINGS['GAINS'] % (winner, score))
self.saveScores(self.players.keys(), winner, score, (datetime.now() - self.startTime).seconds)
except Exception, e:
print 'Score error: %s' % e
self.players = dict()
self.playerOrder = list()
self.game_on = False
self.currentPlayer = 0
self.topCard = None
self.way = 1
self.dealt = False
# Trigger event
onGameEnd(jenni)
def incPlayer(self):
self.currentPlayer = self.currentPlayer + self.way
if self.currentPlayer == len(self.players):
self.currentPlayer = 0
if self.currentPlayer < 0:
self.currentPlayer = len(self.players) - 1
def saveScores(self, players, winner, score, time):
try:
saveScores(players, winner, score, time)
except Exception, e:
print 'Failed to saveon SQL db %s' % e
def showTopCard_demand(self, jenni):
if not self.game_on or not self.deck:
return
jenni.say(STRINGS['TOP_CARD'] % (self.playerOrder[self.currentPlayer], self.renderCards(None, [self.topCard], 1)))
def leave(self, jenni, input):
nickk = (input.nick)
self.remove_player(jenni, nickk)