Browse Source

files var replaced with get_files() function so it can update immediately after changing channel.

channels-redux
cmccabe 3 years ago
parent
commit
a61828cbea
  1. 15
      gab

15
gab

@ -4,6 +4,9 @@ import sys
import time
from datetime import datetime
chan_dir = ".config/gab/channels" ## not used yet. todo: move all gab channel logs to this dir
log = {}
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\n-c, --channel, channel Name of another channel you would like to load"
title = "\033[1mGAB v2.1\033[0m"
@ -27,10 +30,8 @@ def blocked_users():
with open(fp, 'r') as blockfile:
return blockfile.read().split("\n")
chan = get_chan()
files = [[x, "/home/{}/.{}".format(x, get_chan())] for x in os.listdir("/home/") if x not in blocked_users()]
log = {}
def get_files():
return [[x, "/home/{}/.{}".format(x, get_chan())] for x in os.listdir("/home/") if x not in blocked_users()]
def read_file(user, path, num_lines):
global log
@ -49,7 +50,7 @@ def read_file(user, path, num_lines):
def list_messages(count="5"):
global log
global files
files = get_files()
try:
count = int(count)
@ -109,7 +110,7 @@ def add_message(msg):
user = os.environ.get('USER')
timestamp = str(time.time())
output = "{}|{}\n".format(timestamp, msg.strip())
fp = "/home/{}/.{}".format(user, chan)
fp = "/home/{}/.{}".format(user, get_chan())
try:
with open(fp, 'r') as original:
data = original.read(12000)
@ -177,8 +178,6 @@ def switch_channel(newchan):
with open(fp, 'w') as chanfile:
chanfile.write(newchan)
global chan
chan = newchan
print("You are now viewing the '{}' channel.".format(newchan))
list_messages()

Loading…
Cancel
Save