Skip to content

Commit

Permalink
Merge branch 'master' into pyup-update-asynctest-0.9.0-to-0.10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nsavch committed Mar 12, 2017
2 parents 9e1dd75 + 6dee1a9 commit 0090a7a
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 16 deletions.
24 changes: 12 additions & 12 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
aiodns==1.1.1
aioes==0.6.1
-e git+https://github.com/nsavch/aioes#egg=aioes
aiohttp==1.0.5
aioresponses==0.1.2
appnope==0.1.0
async-timeout==1.1.0
asynctest==0.10.0
bottom==1.0.4
cchardet==1.1.2
bottom==1.1.0
cchardet==1.1.3
chardet==2.3.0
clint==0.5.1
colored==1.3.3
colored==1.3.4
cookies==2.2.1
coverage==4.2
coverage==4.3.4
decorator==4.0.10
geoip2==2.4.2
inflection==0.3.1
ipython==5.1.0
ipython==5.3.0
ipython-genutils==0.1.0
maxminddb==1.2.2
maxminddb==1.2.3
multidict==2.1.4
pexpect==4.2.1
pickleshare==0.7.4
pkginfo==1.4.1
prompt-toolkit==1.0.9
prompt-toolkit==1.0.13
ptyprocess==0.5.1
py==1.4.31
py==1.4.32
pycares==2.1.1
pycparser==2.17
Pygments==2.1.3
pytest==3.0.5
pytest==3.0.6
pytest-cov==2.4.0
pytest-mock==1.5.0
pytz==2016.10
PyYAML==3.12
simplegeneric==0.8.1
simplex==0.1.2
six==1.10.0
traitlets==4.3.1
traitlets==4.3.2
twine==1.8.1
wcwidth==0.1.7
yarl==0.8.1
yarl==0.9.8
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
'aiodns==1.1.1',
'aiohttp==1.0.5',
'bottom==1.0.4',
'cchardet==1.1.2',
'cchardet==1.1.3',
'geoip2==2.4.2',
'maxminddb==1.2.2',
'pytz==2016.10',
'PyYAML==3.12',
'aioes==0.6.1'
# 'aioes==0.6.1'
],
classifiers=[
'Development Status :: 3 - Alpha',
Expand Down
36 changes: 35 additions & 1 deletion xanmel/modules/xonotic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,41 @@

class XonoticModule(Module):
db_indices = {
'map_rating': {}
'map_rating': {
"vote": {
"properties": {
"map": {
"type": "keyword",
"index": "not_analyzed"
},
"message": {
"type": "string",
"analyzer": "english"
},
"nickname": {
"type": "keyword",
"index": "not_analyzed"
},
"raw_nickname": {
"type": "keyword",
"index": "not_analyzed"
},
"server_id": {
"type": "long"
},
"stats_id": {
"type": "long"
},
"timestamp": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
},
"vote": {
"type": "long"
}
}
}
}
}

def __init__(self, xanmel, config):
Expand Down
6 changes: 5 additions & 1 deletion xanmel/modules/xonotic/chat_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from xanmel import CommandContainer, ChatCommand

from .colors import Color
from .events import PlayerRatedMap

logger = logging.getLogger(__name__)

Expand All @@ -28,11 +29,14 @@ async def run(self, user, message, is_private=True, root=None):
old_vote = rcon_server.map_voter.votes[user.number2]
if old_vote['vote'] == self.vote and old_vote['message'] == message:
await user.private_reply('You have already voted this round. Enough. You can change your vote though.')
player = rcon_server.players.players_by_number2[user.number2]
rcon_server.map_voter.votes[user.number2] = {
'vote': self.vote,
'message': message,
'player': rcon_server.players.players_by_number2[user.number2]
'player': player
}
PlayerRatedMap(rcon_server.module, server=rcon_server, player=player,
map_name=rcon_server.map_voter.map_name, vote=self.vote).fire()
await user.private_reply('Your vote for map %s is accepted: %s%s' % (
rcon_server.map_voter.map_name,
self.prefix,
Expand Down
7 changes: 7 additions & 0 deletions xanmel/modules/xonotic/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,10 @@ class MapChange(Event):

def __str__(self):
return 'Map change: %s -> %s' % (self.properties['old_map'], self.properties['new_map'])


class PlayerRatedMap(Event):
def __str__(self):
return 'Player %s rated map %s: %s' % (Color.dp_to_none(self.properties['player'].nickname),
self.properties['map_name'],
self.properties['vote'])
54 changes: 54 additions & 0 deletions xanmel/modules/xonotic/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,60 @@ async def handle(self, event):
await server.map_voter.store(event.properties['new_map']) # what if someone votes while this is executing? Oh shi...


class RatingReportHandler(Handler):
events = [MapChange]

async def handle(self, event):
server = event.properties['server']
map_name = server.status['map']
es = server.module.xanmel.db.es
if es is None:
return
await asyncio.sleep(15)
data = await es.search('map_rating', doc_type='vote', body={
'size': 0,
'query': {
'bool': {
'must': [
{'term': {'map': map_name}},
{'term': {'server_id': server.config['unique_id']}}
]
}
},
'aggs': {
'rating': {'sum': {'field': 'vote'}}
}
})
total_votes = data.get('hits', {}).get('total', 0)
rating = data.get('aggregations', {}).get('rating', {}).get('value', 0)
rating = int(rating)
if total_votes == 0:
message = '^3%(map_name)s ^7has not yet been rated - Use ^7/^2+++^7,^2++^7,^2+^7,^1-^7,^1--^7,^1--- ^7to rate the map.'
else:
message = '^3%(map_name)s ^7has ^2%(rating)s ^7points. ^5[%(total_votes)s votes]^7 - Use ^7/^2+++^7,^2++^7,^2+^7,^1-^7,^1--^7,^1--- ^7to rate the map.'
msg_args = {'map_name': map_name, 'rating': rating, 'total_votes': total_votes}
in_game_message = message % msg_args
if server.config['say_type'] == 'ircmsg':
server.send('sv_cmd ircmsg ^7%s' % in_game_message)
else:
with server.sv_adminnick('*'):
server.send('say %s' % in_game_message)
await self.run_action(ChannelMessage, message='\00303%(map_name)s\x0f: \00304%(rating)s\x0f points (\00312%(total_votes)s\x0f votes)' % msg_args,
prefix=server.config['out_prefix'])


class PlayerRatedMapHandler(Handler):
events = [PlayerRatedMap]

async def handle(self, event):
msg = '\00303*\x0f %(player_name)s rated map \00304%(map_name)s\x0f: \00312%(vote)s\x0f'
await self.run_action(ChannelMessage, message=msg % {
'player_name': Color.dp_to_irc(event.properties['player'].nickname).decode('utf8'),
'map_name': event.properties['map_name'],
'vote': event.properties['vote']
}, prefix=event.properties['server'].config['out_prefix'])


class GameStartedHandler(Handler):
events = [GameStarted]

Expand Down

0 comments on commit 0090a7a

Please sign in to comment.