Skip to content

Commit

Permalink
Fixes crucial bug introduced in 0.6.7; also fixes #11
Browse files Browse the repository at this point in the history
  • Loading branch information
double-fault committed Jan 14, 2019
1 parent 2c81222 commit 24e532e
Show file tree
Hide file tree
Showing 13 changed files with 113 additions and 200 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Some incomplete documentation of Botpy exists here: https://botpy.readthedocs.io

# Changelog

- **v0.7.3**: Finally fixes the bug introduced in 0.6.7. All default commands have been moved to `AllCommands.py`; this also fixes #11.
- **v0.7.2**: Another attempt at 0.7.1.
- **v0.7.1**: Fixes bug introduced in 0.6.7.
- **v0.7.0**: Allow multiple aliases for a bot; #7.
Expand Down
120 changes: 111 additions & 9 deletions Source/AllCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,117 @@
# Botpy
#
# Created by Ashish Ahuja on 13th January 2019.
# Licensed under WTFPL.
#

from Commands.CommandAlive import CommandAlive
from Commands.CommandListRunningCommands import CommandListRunningCommands
from Commands.CommandPrivilegeUser import CommandPrivilegeUser
from Commands.CommandStop import CommandStop
from Commands.CommandUnprivilegeUser import CommandUnprivilegeUser
from Commands.CommandAmiprivileged import CommandAmiprivileged
from Commands.CommandListPrivilegedUsers import CommandListPrivilegedUsers
from Commands.CommandReboot import CommandReboot
from Commands.Command import Command
from .Command import *
from . import Utilities

import tabulate
import re

class CommandAlive(Command):
@staticmethod
def usage():
return ["alive", "status"]

def run(self):
self.reply("Yes")

class CommandAmiprivileged(Command):
def usage():
return ["amiprivileged", "doihaveprivs", "privileges"]

def run(self):
user_privs = self.message.user.get_privilege_type()
if user_privs is None:
self.reply("You do not have any privileges.")
else:
self.reply("You have the privilege: " + user_privs.name)

class CommandListPrivilegedUsers(Command):
def usage():
return ["membership", "privileged", "listprivileged"]

def run(self):
privilege_list = list()

for each_user in self.message.room.get_users():
if each_user.get_privilege_type() is not None:
privilege_list.append([each_user.id, each_user.get_privilege_type().name])

table = tabulate.tabulate(privilege_list, headers=["User ID", "Privilege level"], tablefmt="orgtbl")

self.post(" " + table.replace("\n", "\n "))

class CommandListRunningCommands(Command):
@staticmethod
def usage():
return ["running commands", "rc"]

def run(self):
command_list = list()

for each_command, _ in self.command_manager.running_commands:
command_list.append([each_command.message.user.name, each_command.usage()[each_command.usage_index]])

table = tabulate.tabulate(command_list, headers=["User", "Command"], tablefmt="orgtbl")

self.post(" " + re.sub('\n', '\n ', table))

class CommandPrivilegeUser(Command):
def usage():
return ["privilege * *", "addpriv * *"]

def privileges(self):
return 0

def run(self):
user_id = int(self.arguments[0])
privilege_name = self.arguments[1]

privilege_type = self.message.room.get_privilege_type_by_name(privilege_name)

if privilege_type == None:
self.reply("Please give a valid privilege type")
return

if self.message.room.is_user_privileged(user_id, privilege_type.level):
self.reply("The user specified already has the required privileges.")
return

self.message.room.change_privilege_level(user_id, privilege_type)
self.reply("The user specified has been given the privileges.")

class CommandUnprivilegeUser(Command):
@staticmethod
def usage():
return ["unprivilege *", "unprivilege user *", "remove privileges *"]

def run(self):
user_id = int(self.arguments[0])

self.message.room.change_privilege_level(user_id)
self.reply("The user specified has been stripped of all privileges.")

class CommandReboot(Command):
@staticmethod
def usage():
return ['reboot', 'restart']

def run(self):
self.reply("Rebooting...")
Utilities.StopReason.reboot = True

class CommandStop(Command):
@staticmethod
def usage():
return ['stop', 'shutdown']

def run(self):
self.reply("Shutting down...")
Utilities.StopReason.shutdown = True




File renamed without changes.
18 changes: 0 additions & 18 deletions Source/Commands/CommandAlive.py

This file was deleted.

21 changes: 0 additions & 21 deletions Source/Commands/CommandAmiprivileged.py

This file was deleted.

27 changes: 0 additions & 27 deletions Source/Commands/CommandListPrivilegedUsers.py

This file was deleted.

29 changes: 0 additions & 29 deletions Source/Commands/CommandListRunningCommands.py

This file was deleted.

34 changes: 0 additions & 34 deletions Source/Commands/CommandPrivilegeUser.py

This file was deleted.

20 changes: 0 additions & 20 deletions Source/Commands/CommandReboot.py

This file was deleted.

20 changes: 0 additions & 20 deletions Source/Commands/CommandStop.py

This file was deleted.

21 changes: 0 additions & 21 deletions Source/Commands/CommandUnprivilegeUser.py

This file was deleted.

Empty file removed Source/Commands/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
setup (
name = "BotpySE",
packages = ["BotpySE"],
version = "0.7.2",
version = "0.7.3",
description = "A python framework to create chatbots on the StackExchange network.",
author = "Ashish Ahuja",
author_email = "[email protected]",
Expand Down

0 comments on commit 24e532e

Please sign in to comment.