-
Notifications
You must be signed in to change notification settings - Fork 9
/
intermission.py
115 lines (94 loc) · 4.52 KB
/
intermission.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# This is a plugin created by iouonegirl(@gmail.com)
# Copyright (c) 2016,2017 iouonegirl
# https://github.com/dsverdlo/minqlx-plugins
#
# You are free to modify this plugin to your custom,
# except for the version command related code.
#
# Original idea from <roasticle>, but edited to support
# a list of sounds which will be played one by one after each match.
#
# Place the sounds files in a PK3 file and upload it to a workshop.
#
# If you have trouble hearing the music, I heard Mino's
# workshop.py plugin helps.
import minqlx
import time
import requests
VERSION = "v0.30"
# These songs will be looped one by one. Don't forget to remove the #'s if you want to use songs
# or set the cvar qlx_intermission_songs to a comma-delimited list of songs in server.cfg, like:
# set qlx_intermission_songs "sound/songname/songtitle1.ogg,sound/songname/songtitle2.ogg,sound/songname/songtitle3.ogg"
SONGS = [
#"sound/songname/songtitle1.ogg",
#"sound/songname/songtitle2.ogg",
#"sound/songname/songtitle3.ogg",
]
# When qlx_intermission_songs has been set, then the value of SONGS is ignored.
class intermission(minqlx.Plugin):
def __init__(self):
self.index = 0
self.set_cvar_once( "qlx_intermission_songs", ",".join(SONGS) )
self.songs = self.get_cvar( "qlx_intermission_songs", list )
if not self.songs:
self.msg("^1Error: No song list for intermission.^7")
return
self.add_hook("game_end", self.handle_game_end)
self.add_hook("player_connect", self.handle_player_connect)
self.add_command("v_intermission", self.cmd_version)
self.add_command("intermission", self.cmd_intermission, 3 )
def cmd_intermission( self, player, msg, channel):
for p in self.players():
if self.db.get_flag(p, "essentials:sounds_enabled", default=True):
self.stop_sound(p)
self.handle_game_end( { "ABORTED":0 } )
x = 0
for x, song in enumerate(self.songs):
channel.reply( "{}{}".format( song, " (now playing)" if x == self.index else "" ) )
x += 1
@minqlx.delay(0.3)
def handle_game_end(self, data ):
# If there are no songs defined, return
if not self.songs or data["ABORTED"]:
return
# If last time the index was incremented too high, loop around
if self.index >= len(self.songs):
self.index = 0
# Try to play sound file
try:
for p in self.players():
if self.db.get_flag(p, "essentials:sounds_enabled", default=True):
self.stop_music(p)
self.play_sound(self.songs[self.index],p)
except Exception as e:
self.msg("^1Error: ^7{}".format(e))
# Increase the counter so next round the next sound will be played
self.index += 1
def handle_player_connect(self, player):
if self.db.has_permission(player, 5):
self.check_version(player=player)
def cmd_version(self, player, msg, channel):
self.check_version(channel=channel)
@minqlx.thread
def check_version(self, player=None, channel=None):
url = "https://raw.githubusercontent.com/dsverdlo/minqlx-plugins/master/{}.py".format(self.__class__.__name__)
res = requests.get(url)
last_status = res.status_code
if res.status_code != requests.codes.ok: return
for line in res.iter_lines():
if line.startswith(b'VERSION'):
line = line.replace(b'VERSION = ', b'')
line = line.replace(b'"', b'')
# If called manually and outdated
if channel and VERSION.encode() != line:
channel.reply("^7Currently using ^3iou^7one^4girl^7's ^6{}^7 plugin ^1outdated^7 version ^6{}^7.".format(self.__class__.__name__, VERSION))
# If called manually and alright
elif channel and VERSION.encode() == line:
channel.reply("^7Currently using ^3iou^7one^4girl^7's latest ^6{}^7 plugin version ^6{}^7.".format(self.__class__.__name__, VERSION))
# If routine check and it's not alright.
elif player and VERSION.encode() != line:
time.sleep(15)
try:
player.tell("^3Plugin update alert^7:^6 {}^7's latest version is ^6{}^7 and you're using ^6{}^7!".format(self.__class__.__name__, line.decode(), VERSION))
except Exception as e: minqlx.console_command("echo {}".format(e))
return