diff options
author | Karel Kočí <cynerd@email.cz> | 2016-10-23 12:53:45 +0200 |
---|---|---|
committer | Karel Kočí <cynerd@email.cz> | 2016-10-23 12:53:45 +0200 |
commit | f556c681a5afae36a7d7c11ade5854a6de4a0896 (patch) | |
tree | 90d4442c0b5a20fc589faf9e10866b8eba868e37 /mcwrapper/mod.py | |
parent | fcbf1c073d90c09e27b2ba69ca62b89ad6e1b063 (diff) | |
download | mcserver-wrapper-f556c681a5afae36a7d7c11ade5854a6de4a0896.tar.gz mcserver-wrapper-f556c681a5afae36a7d7c11ade5854a6de4a0896.tar.bz2 mcserver-wrapper-f556c681a5afae36a7d7c11ade5854a6de4a0896.zip |
Add message of the day feature
Diffstat (limited to 'mcwrapper/mod.py')
-rw-r--r-- | mcwrapper/mod.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/mcwrapper/mod.py b/mcwrapper/mod.py new file mode 100644 index 0000000..78ffb8e --- /dev/null +++ b/mcwrapper/mod.py @@ -0,0 +1,24 @@ +# vim: expandtab ft=python ts=4 sw=4 sts=4: +import random + +from . import alarm + + +class MoD: + "Message of the day handler" + def __init__(self, mcwrapper, file, period=900): + self.mcwrapper = mcwrapper + self.file = file + self.load_mods() + alarm.set("mod-time", period, self.__handler__, repeat=True) + + def load_mods(self): + "Loads messages from self.file" + with open(self.file, "r") as f: + self.lines = f.readlines() + + def __handler__(self): + if len(self.lines) > 0: + i = random.randint(0, len(self.lines) - 1) + self.mcwrapper.write_to_terminal("/say " + self.lines[i].rstrip() + + "\n") |