| Total Complexity | 4 |
| Total Lines | 19 |
| Duplicated Lines | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
| 1 | from base import BotPlugin |
||
| 6 | class Uptime(BotPlugin): |
||
| 7 | |||
| 8 | def _uptime(self, tokens, channel): |
||
| 9 | try: |
||
| 10 | with open("/proc/uptime", 'r') as f: |
||
| 11 | server_uptime_seconds = int(float(f.readline().split()[0])) |
||
| 12 | server_uptime = str(timedelta(seconds=server_uptime_seconds)) |
||
| 13 | except Exception: |
||
| 14 | self.bot.log_error('Could not get server uptime.') |
||
| 15 | server_uptime = "unknown" |
||
| 16 | |||
| 17 | bot_uptime_seconds = int(time() - self.bot.start_time) |
||
| 18 | bot_uptime = str(timedelta(seconds=bot_uptime_seconds)) |
||
| 19 | self.bot.say("My uptime: %s, server uptime: %s" |
||
| 20 | % (bot_uptime, server_uptime), |
||
| 21 | channel) |
||
| 22 | |||
| 23 | def handle_message(self, channel, nick, msg, line=None): |
||
| 24 | self.handle_tokens(channel, msg, ('uptime',), self._uptime) |
||
| 25 |