Browse Source

-c option changes channel

channels-redux
cmccabe 3 years ago
parent
commit
2b53796c48
  1. 32
      gab

32
gab

@ -7,6 +7,15 @@ 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\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 get_chan():
current_user = os.environ.get('USER')
fp = "/home/{}/.gab_chan".format(current_user)
if not os.path.isfile(fp):
return "gab"
with open(fp, 'r') as chanfile:
return chanfile.read().split("\n")[0]
def blocked_users():
current_user = os.environ.get('USER')
@ -18,8 +27,9 @@ def blocked_users():
with open(fp, 'r') as blockfile:
return blockfile.read().split("\n")
chan = get_chan()
files = [[x, "/home/{}/.gab".format(x)] for x in os.listdir("/home/") if x not in blocked_users()]
files = [[x, "/home/{}/.{}".format(x, get_chan())] for x in os.listdir("/home/") if x not in blocked_users()]
log = {}
def read_file(user, path, num_lines):
@ -99,7 +109,7 @@ def add_message(msg):
user = os.environ.get('USER')
timestamp = str(time.time())
output = "{}|{}\n".format(timestamp, msg.strip())
fp = "/home/{}/.gab".format(user)
fp = "/home/{}/.{}".format(user, chan)
try:
with open(fp, 'r') as original:
data = original.read(12000)
@ -160,6 +170,16 @@ def unblock_user(user_to_unblock):
print("User '{}' has been removed from your block list".format(user_to_unblock))
def switch_channel(chan):
current_user = os.environ.get('USER')
fp = "/home/{}/.gab_chan".format(current_user)
with open(fp, 'w') as chanfile:
chanfile.write(chan)
print("You are now viewing the '{}' channel.".format(chan))
list_messages()
def parse_command():
args = sys.argv[1:]
@ -193,6 +213,14 @@ def parse_command():
print("Received too many arguments")
else:
unblock_user(args[1])
elif args[0] in ["-c", "--channel", "channel"]:
if len(args) < 2:
print("Returning to default channel.")
switch_channel("gab")
elif len(args) > 2:
print("Expected a channel to join, but one was not received.")
else:
switch_channel(args[1])
else:
print("Unknown command: {}".format(args[0]))

Loading…
Cancel
Save