Skip to content

Commit

Permalink
Added a delete command, new ranks
Browse files Browse the repository at this point in the history
Added the delete command (fixes #24)
Added new flag ranks (by Zoe and Paul Stenne) (#11)
  • Loading branch information
Filnor committed Apr 25, 2018
1 parent 8ee5c66 commit b12d250
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 38 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,7 @@ ENV/
/keyrings/live/secring.gpg

# config file
config.py
config.py

# Bash scripts
*.sh
54 changes: 21 additions & 33 deletions checkyerflags.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def main():
utils.client = client
room = client.get_room(utils.config["room"])
room.join()
room.watch(on_message)
room.watch_socket(on_message)
print(room.get_current_user_names())
utils.room_owners = room.owners
#endregion
Expand All @@ -58,7 +58,7 @@ def main():
if quota_obj['quota_remaining'] is not None:
utils.quota = quota_obj['quota_remaining']

logging.basicConfig(filename="CheckYerFlags.log", level=logging.INFO, filemode="w")
logging.basicConfig(filename="CheckYerFlags.log", level=logging.INFO, filemode="a")
logging.getLogger("chatexchange").setLevel(logging.WARNING)
logging.getLogger().addHandler(logging.StreamHandler(sys.stdout))

Expand Down Expand Up @@ -99,7 +99,11 @@ def main():

while True:
message = input("<< ")
room.send_message(message)

if message == "restart":
os._exit(1)
else:
room.send_message(message)

#client.logout()
#stop_redunda.set()
Expand All @@ -115,20 +119,19 @@ def on_message(message, client):
logging.warning(message)
return

if message.user.id == 9220325:
utils.last_bot_message = message

try:
#Here are the commands defined
if utils.check_aliases(message_val, "amiprivileged"):
if utils.check_aliases(message_val, "del") or utils.check_aliases(message_val, "delete"):
msg = client.get_message(utils.last_bot_message._message_id)
if msg is not None:
msg.delete()
elif utils.check_aliases(message_val, "amiprivileged"):
logging.info("amiprivileged command was called")

room_owner_id_list = []
for owner in utils.room_owners:
room_owner_id_list.append(owner.id)

if 4733879 not in room_owner_id_list:
room_owner_id_list.append(4733879)

# Restrict function to (site) moderators, room owners and maintainers
if message.user.is_moderator or message.user.id in room_owner_id_list:
if utils.is_privileged(message):
utils.reply_with(message, "You are privileged.")
else:
utils.reply_with(message, "You are not privileged. Ping chade_ if you believe that's an error.")
Expand All @@ -155,37 +158,22 @@ def on_message(message, client):
utils.post_message("The remaining API quota is {}.".format(utils.quota))
elif utils.check_aliases(message_val, "kill") or utils.check_aliases(message_val, "stop"):
logging.info("kill command was called")
logging.warning("Termination or stop requested by {}".format(message.user.name))

room_owner_id_list = []
for owner in utils.room_owners:
room_owner_id_list.append(owner.id)

if 4733879 not in room_owner_id_list:
room_owner_id_list.append(4733879)

# Restrict function to (site) moderators, room owners and maintainers
if message.user.is_moderator or message.user.id in room_owner_id_list:
logging.warning("Termination or stop requested by {}".format(message.user.name))
if utils.is_privileged(message):
try:
utils.client.get_room(utils.room_number).leave()
except BaseException:
pass
raise SystemExit(0)
raise os._exit(0)
else:
utils.reply_with(message, "This command is restricted to moderators, room owners and maintainers. (cc @chade_)")
elif utils.check_aliases(message_val, "leave") or utils.check_aliases(message_val, "bye"):
logging.info("leave command was called")

room_owner_id_list = []
for owner in utils.room_owners:
room_owner_id_list.append(owner.id)

if 4733879 not in room_owner_id_list:
room_owner_id_list.append(4733879)
logging.warning("Leave requested by {}".format(message.user.name))

# Restrict function to (site) moderators, room owners and maintainers
if message.user.is_moderator or message.user.id in room_owner_id_list:
logging.warning("Leave requested by {}".format(message.user.name))
if utils.is_privileged(message):
utils.post_message("Bye")
utils.client.get_room(utils.room_number).leave()
else:
Expand Down
8 changes: 4 additions & 4 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<meta name="description" content="">
<meta name="author" content="">
<link rel="shortcut icon" href="favicon.png">
<link href='http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800' rel='stylesheet' type='text/css'>
<!-- Global CSS -->
<link rel="stylesheet" href="assets/plugins/bootstrap/css/bootstrap.min.css">
<!-- Plugins CSS -->
Expand Down Expand Up @@ -240,9 +240,9 @@ <h3 class="block-title">List of ranks</h3>
<td><a href="https://stackoverflow.com/users/4687348/felixsfd" rel="nofollow">FelixSFD</a></td>
</tr>
<tr>
<td><del>811</del></td>
<td><del>How dare thy!</del></td>
<td><del>811 is Shog's user id</del></td>
<td>811</td>
<td>How dare thy!</td>
<td>I think you know whose user id that is</td>
<td><a href="https://stackoverflow.com/users/4174897/paul-stenne" rel="nofollow">Paul Stenne</a></td>
</tr>
<tr>
Expand Down
40 changes: 40 additions & 0 deletions flagbot/ranks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,21 @@
"title": "A flag a day keeps bad posts away",
"description": "One year has 365 days"
},
{
"count": 811,
"title": "How thare thy?",
"description": "I think you know whose user id that is"
},
{
"count": 1111,
"title": "No badge needed",
"description": "A number is prettier than a badge anyway!"
},
{
"count": 1337,
"title": "l337 fl4663r",
"description": "[l337 5p34k 15 4w350m3!](https://en.wikipedia.org/wiki/Leet)"
},
{
"count": 1969,
"title": "Moon landing",
Expand All @@ -19,6 +29,11 @@
"title": "Flag Overflow",
"description": "Stack Overflow was created in 2008"
},
{
"count": 2395,
"title": "Flag me up, Scotty",
"description": "[We don't beam, we flag](https://en.wikipedia.org/wiki/Beam_me_up,_Scotty)"
},
{
"count": 3456,
"title": "<3456",
Expand All @@ -39,6 +54,11 @@
"title": "Game of Flags",
"description": "All elevens because the TV show Game of Thrones started in 2011"
},
{
"count": 19679,
"title": "Professional Larnsonist",
"description": "19679 is Brad Larnson's user id"
},
{
"count": 22656,
"title": "Almost Jon Skeet",
Expand Down Expand Up @@ -69,6 +89,26 @@
"title": "π",
"description": "Who ate all the Pi?"
},
{
"count": 874188,
"title": "tripleee",
"description": "Wheeereee has theee eee goneee?"
},
{
"count": 1849664,
"title": "Woof woof",
"description": "1849664 is Undo's user id"
},
{
"count": 3735529,
"title": "He just does the pointing job",
"description": "3735529 is Smokey's user id"
},
{
"count": 4733879,
"title": "Call me flaggy",
"description": "4733879 is chade_'s user id"
},
{
"count": 2147483647,
"title": "The Overflow",
Expand Down
11 changes: 11 additions & 0 deletions flagbot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ def check_aliases(self, message, command):
else:
return False

def is_privileged(self, message):
priviledged_users = [4733879]
for owner in self.room_owners:
priviledged_users.append(owner.id)

# Restrict function to (site) moderators, room owners and maintainers
if message.user.is_moderator or message.user.id in priviledged_users:
return True
else:
return False

@staticmethod
def reply_with(message, reply):
logging.info(message)
Expand Down

0 comments on commit b12d250

Please sign in to comment.