Merge branch 'blocking' of sloum/gab2 into master

This has been tested on rawtext.club as functional.
action-support
Sloom Sloum Sluom IV 3 years ago committed by Gitea
commit bbae157376
  1. 71
      gab

71
gab

@ -4,9 +4,22 @@ import sys
import time
from datetime import datetime
help_text = "GAB - A simple chat interface\n\nsyntax: gab [flag] [value]\n\nflag value\n---------------- ---------------\n-h, --help, help None\n-m, --msg, msg Quoted text with the msg being added to chat\n-l, --list, list An integer representing the number of rows you\'d like to view, default 5"
title = "\033[1mGAB v2.0\033[0m"
files = [[x, "/home/{}/.gab".format(x)] for x in os.listdir("/home/")]
help_text = "GAB - A simple chat interface\n\nsyntax: gab [flag] [value]\n\nflag value\n-------------------- ---------------\n-h, --help, help None\n-m, --msg, msg Quoted text with the msg being added to chat\n-l, --list, list An integer representing the number of rows you\'d like to view, default 5\n-b, --block, block A username to block/ignore\n-u, --unblock, unblock A username to unblock/unignore"
title = "\033[1mGAB v2.1\033[0m"
def blocked_users():
current_user = os.environ.get('USER')
fp = "/home/{}/.gab_block".format(current_user)
if not os.path.isfile(fp):
return []
with open(fp, 'r') as blockfile:
return blockfile.read().split("\n")
files = [[x, "/home/{}/.gab".format(x)] for x in os.listdir("/home/") if x not in blocked_users()]
log = {}
def read_file(user, path, num_lines):
@ -96,6 +109,44 @@ def add_message(msg):
print("The chatlog does not exist")
def block_user(user_to_block):
current_user = os.environ.get('USER')
fp = "/home/{}/.gab_block".format(current_user)
block_fp = "/home/{}/".format(user_to_block)
if not os.path.isdir(block_fp):
print("User '{}' does not exist, no action taken".format(user_to_block))
return
with open(fp, 'a') as blockfile:
blockfile.write(user_to_block)
blockfile.write("\n")
print("User '{}' has been blocked, you will not see their messages".format(user_to_block))
return
def unblock_user(user_to_unblock):
current_user = os.environ.get('USER')
fp = "/home/{}/.gab_block".format(current_user)
unblock_fp = "/home/{}/".format(user_to_unblock)
if not os.path.isfile(fp):
print("You do not have any users on your block list, no action taken")
return
if not os.path.isdir(unblock_fp):
print("User '{}' does not exist, no action taken".format(user_to_unblock))
return
blocked_users_list = [x for x in blocked_users() if x != user_to_unblock]
with open(fp, 'w') as blocked:
blocked.write("\n".join(blocked_users_list))
print("User '{}' has been removed from your block list".format(user_to_unblock))
def parse_command():
args = sys.argv[1:]
if not len(args):
@ -114,6 +165,20 @@ def parse_command():
print("Received too many arguments")
else:
add_message(args[1])
elif args[0] in ["-b", "--block", "block"]:
if len(args) < 2:
print("Expected a user to block, but one was not received")
elif len(args) > 2:
print("Received too many arguments")
else:
block_user(args[1])
elif args[0] in ["-u", "--unblock", "unblock"]:
if len(args) < 2:
print("Expected a user to block, but one was not received")
elif len(args) > 2:
print("Received too many arguments")
else:
unblock_user(args[1])
else:
print("Unknown command: {}".format(args[0]))

Loading…
Cancel
Save