-
Notifications
You must be signed in to change notification settings - Fork 0
/
VolBot.py
executable file
·79 lines (67 loc) · 2.7 KB
/
VolBot.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
#!/usr/bin/env python
# This file is part of GrooveBot.
#
# GrooveBot is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# GrooveBot is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GrooveBot. If not, see <http://www.gnu.org/licenses/>.
import math
from twisted.internet import reactor, utils
from JlewBot import JlewBotFactory, JlewBot
import util
class VolBot(JlewBot):
bot_name = "foss_volbot"
channel = "#rit-groove"
versionNum = 1.3
sourceURL = "https://github.com/Qalthos/groovebot"
alsa_channel = 'Master'
volume_scale = 'logarithmic'
vol_step = 5
vol = 50
def setup(self, f):
f.register_command('vol', self.volume_change)
f.register_command('source', self.simple_response)
reactor.callWhenRunning(self._set_vol)
def volume_change(self, responder, user, channel, command, msg):
if command == "vol":
if not msg:
responder(self.vol)
else:
if msg == "up":
if self.vol < 100:
self.vol += self.vol_step
self._set_vol().addCallback(util.ok, responder, str(self.vol)).addErrback(util.err_chat, responder)
else:
responder("Volume maxed.")
elif msg == "down":
if self.vol > 0:
self.vol -= self.vol_step
self._set_vol().addCallback(util.ok, responder, str(self.vol)).addErrback(util.err_chat, responder)
else:
responder("Muted.")
def simple_response(self, responder, user, channel, command, msg):
""" This is a method that just responds with simple strings."""
if command == "source":
responder(self.sourceURL)
def _set_vol(self):
volume = self.vol
if self.volume_scale == 'linear' and volume > 0:
volume = math.log10(volume) * 50
return utils.getProcessValue(
'/usr/bin/amixer',
['sset', self.alsa_channel, '%d%%' % volume]
)
if __name__ == '__main__':
bot = VolBot()
f = JlewBotFactory(protocol=VolBot)
bot.setup(f)
reactor.connectTCP("irc.freenode.net", 6667, f)
reactor.run()