Compare commits
4 Commits
315a249ef6
...
9488ade7fb
Author | SHA1 | Date | |
---|---|---|---|
|
9488ade7fb | ||
|
ee85dfe5ab | ||
|
5c708b436b | ||
|
68253447b7 |
@ -29,18 +29,27 @@ from getpass import getpass
|
|||||||
from subprocess import call
|
from subprocess import call
|
||||||
from random import choice
|
from random import choice
|
||||||
from code import interact
|
from code import interact
|
||||||
from sys import exit
|
|
||||||
import rlcompleter
|
import rlcompleter
|
||||||
import readline
|
import readline
|
||||||
import tempfile
|
import tempfile
|
||||||
import shlex
|
|
||||||
import urwid
|
import urwid
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
|
||||||
help_text = """\
|
# XxX_N0_4rgP4rs3_XxX ###yoloswag
|
||||||
BBJ Urwid Client
|
def get_arg(key, default=None, get_value=True):
|
||||||
|
try:
|
||||||
|
spec = argv.index("--" + key)
|
||||||
|
value = argv[spec + 1] if get_value else True
|
||||||
|
except ValueError: # --key not specified
|
||||||
|
value = default
|
||||||
|
except IndexError: # flag given but no value
|
||||||
|
exit("invalid format for --" + key)
|
||||||
|
return value
|
||||||
|
|
||||||
|
if get_arg("help", False, False):
|
||||||
|
print("""BBJ Urwid Client
|
||||||
Available options:
|
Available options:
|
||||||
--help: this message
|
--help: this message
|
||||||
--https: enable use of https, requires host support
|
--https: enable use of https, requires host support
|
||||||
@ -53,7 +62,16 @@ Available environment variables:
|
|||||||
BBJ_PASSWORD: set your password to log in automatically.
|
BBJ_PASSWORD: set your password to log in automatically.
|
||||||
if the password is wrong, will prompt you as normal.
|
if the password is wrong, will prompt you as normal.
|
||||||
Please note that these environment variables need to be exported, and are
|
Please note that these environment variables need to be exported, and are
|
||||||
visible to all other programs run from your shell."""
|
visible to all other programs run from your shell.""")
|
||||||
|
exit()
|
||||||
|
|
||||||
|
try:
|
||||||
|
network = BBJ(get_arg("host", "127.0.0.1"),
|
||||||
|
get_arg("port", 7099),
|
||||||
|
get_arg("https", False, False))
|
||||||
|
except URLError as e:
|
||||||
|
# print the connection error in red
|
||||||
|
exit("\033[0;31m%s\033[0m" % repr(e))
|
||||||
|
|
||||||
obnoxious_logo = """
|
obnoxious_logo = """
|
||||||
% _ * ! *
|
% _ * ! *
|
||||||
@ -71,7 +89,7 @@ obnoxious_logo = """
|
|||||||
|
|
||||||
welcome = """>>> Welcome to Bulletin Butter & Jelly! ------------------@
|
welcome = """>>> Welcome to Bulletin Butter & Jelly! ------------------@
|
||||||
| BBJ is a persistent, chronologically ordered text |
|
| BBJ is a persistent, chronologically ordered text |
|
||||||
| discussion board for tilde.town. You may log in, |
|
| discussion board for tildes. You may log in, |
|
||||||
| register as a new user, or participate anonymously. |
|
| register as a new user, or participate anonymously. |
|
||||||
|---------------------------------------------------------|
|
|---------------------------------------------------------|
|
||||||
| \033[1;31mTo go anon, just press enter. Otherwise, give me a name\033[0m |
|
| \033[1;31mTo go anon, just press enter. Otherwise, give me a name\033[0m |
|
||||||
@ -310,8 +328,7 @@ markpath = os.path.join(os.getenv("HOME"), ".bbjmarks")
|
|||||||
pinpath = os.path.join(os.getenv("HOME"), ".bbjpins")
|
pinpath = os.path.join(os.getenv("HOME"), ".bbjpins")
|
||||||
|
|
||||||
class App(object):
|
class App(object):
|
||||||
def __init__(self, network):
|
def __init__(self):
|
||||||
self.network = network
|
|
||||||
self.prefs = bbjrc("load")
|
self.prefs = bbjrc("load")
|
||||||
self.client_pinned_threads = load_client_pins()
|
self.client_pinned_threads = load_client_pins()
|
||||||
self.usermap = {}
|
self.usermap = {}
|
||||||
@ -370,7 +387,7 @@ class App(object):
|
|||||||
bar formatting to it.
|
bar formatting to it.
|
||||||
"""
|
"""
|
||||||
header = ("{}@bbj | " + text).format(
|
header = ("{}@bbj | " + text).format(
|
||||||
(self.network.user_name or "anonymous"),
|
(network.user_name or "anonymous"),
|
||||||
*format_specs
|
*format_specs
|
||||||
)
|
)
|
||||||
self.loop.widget.header = urwid.AttrMap(urwid.Text(header), "bar")
|
self.loop.widget.header = urwid.AttrMap(urwid.Text(header), "bar")
|
||||||
@ -576,7 +593,7 @@ class App(object):
|
|||||||
# first we need to get the server's version of the message
|
# first we need to get the server's version of the message
|
||||||
# instead of our formatted one
|
# instead of our formatted one
|
||||||
try:
|
try:
|
||||||
message = self.network.edit_query(thread_id, post_id)
|
message = network.edit_query(thread_id, post_id)
|
||||||
except UserWarning as e:
|
except UserWarning as e:
|
||||||
self.remove_overlays()
|
self.remove_overlays()
|
||||||
return self.temp_footer_message(e.description)
|
return self.temp_footer_message(e.description)
|
||||||
@ -599,7 +616,7 @@ class App(object):
|
|||||||
urwid.Text(("bold", "Delete this %s?" % ("whole thread" if op else "post"))),
|
urwid.Text(("bold", "Delete this %s?" % ("whole thread" if op else "post"))),
|
||||||
urwid.Divider(),
|
urwid.Divider(),
|
||||||
cute_button(("10" , ">> Yes"), lambda _: [
|
cute_button(("10" , ">> Yes"), lambda _: [
|
||||||
self.network.message_delete(message["thread_id"], message["post_id"]),
|
network.message_delete(message["thread_id"], message["post_id"]),
|
||||||
self.remove_overlays(),
|
self.remove_overlays(),
|
||||||
self.index() if op else self.refresh()
|
self.index() if op else self.refresh()
|
||||||
]),
|
]),
|
||||||
@ -621,7 +638,7 @@ class App(object):
|
|||||||
def toggle_formatting(self, button, message):
|
def toggle_formatting(self, button, message):
|
||||||
self.remove_overlays()
|
self.remove_overlays()
|
||||||
raw = not message["send_raw"]
|
raw = not message["send_raw"]
|
||||||
self.network.set_post_raw(message["thread_id"], message["post_id"], raw)
|
network.set_post_raw(message["thread_id"], message["post_id"], raw)
|
||||||
return self.refresh()
|
return self.refresh()
|
||||||
|
|
||||||
|
|
||||||
@ -638,7 +655,7 @@ class App(object):
|
|||||||
"View %sQuote" % ("a " if len(quotes) != 1 else ""),
|
"View %sQuote" % ("a " if len(quotes) != 1 else ""),
|
||||||
self.quote_view_menu, quotes))
|
self.quote_view_menu, quotes))
|
||||||
|
|
||||||
if self.network.can_edit(message["thread_id"], message["post_id"]) \
|
if network.can_edit(message["thread_id"], message["post_id"]) \
|
||||||
and not self.window_split:
|
and not self.window_split:
|
||||||
|
|
||||||
if message["post_id"] == 0:
|
if message["post_id"] == 0:
|
||||||
@ -651,7 +668,7 @@ class App(object):
|
|||||||
"Enable Formatting" if raw else "Disable Formatting",
|
"Enable Formatting" if raw else "Disable Formatting",
|
||||||
self.toggle_formatting, message))
|
self.toggle_formatting, message))
|
||||||
buttons.insert(0, urwid.Button("Edit Post", self.edit_post, message))
|
buttons.insert(0, urwid.Button("Edit Post", self.edit_post, message))
|
||||||
if self.network.user["is_admin"]:
|
if network.user["is_admin"]:
|
||||||
buttons.insert(0, urwid.Text(("20", "Reminder: You're an admin!")))
|
buttons.insert(0, urwid.Text(("20", "Reminder: You're an admin!")))
|
||||||
|
|
||||||
if not buttons:
|
if not buttons:
|
||||||
@ -804,7 +821,7 @@ class App(object):
|
|||||||
# narrowed selection of content, so we dont want to resume last_index_pos
|
# narrowed selection of content, so we dont want to resume last_index_pos
|
||||||
self.last_index_pos = False
|
self.last_index_pos = False
|
||||||
else:
|
else:
|
||||||
threads, usermap = self.network.thread_index()
|
threads, usermap = network.thread_index()
|
||||||
self.usermap.update(usermap)
|
self.usermap.update(usermap)
|
||||||
self.walker.clear()
|
self.walker.clear()
|
||||||
|
|
||||||
@ -850,7 +867,7 @@ class App(object):
|
|||||||
self.body.attr_map = {None: "default"}
|
self.body.attr_map = {None: "default"}
|
||||||
|
|
||||||
self.mode = "thread"
|
self.mode = "thread"
|
||||||
thread, usermap = self.network.thread_load(thread_id, format="sequential")
|
thread, usermap = network.thread_load(thread_id, format="sequential")
|
||||||
self.usermap.update(usermap)
|
self.usermap.update(usermap)
|
||||||
self.thread = thread
|
self.thread = thread
|
||||||
self.match_data["matches"].clear()
|
self.match_data["matches"].clear()
|
||||||
@ -871,16 +888,16 @@ class App(object):
|
|||||||
|
|
||||||
|
|
||||||
def toggle_server_pin(self):
|
def toggle_server_pin(self):
|
||||||
if self.mode != "index" or not self.network.user["is_admin"]:
|
if self.mode != "index" or not network.user["is_admin"]:
|
||||||
return
|
return
|
||||||
thread = self.walker.get_focus()[0].thread
|
thread = self.walker.get_focus()[0].thread
|
||||||
self.network.thread_set_pin(thread["thread_id"], not thread["pinned"])
|
network.thread_set_pin(thread["thread_id"], not thread["pinned"])
|
||||||
self.index()
|
self.index()
|
||||||
|
|
||||||
|
|
||||||
def search_index_callback(self, query):
|
def search_index_callback(self, query):
|
||||||
simple_query = query.lower().strip()
|
simple_query = query.lower().strip()
|
||||||
threads, usermap = self.network.thread_index()
|
threads, usermap = network.thread_index()
|
||||||
self.usermap.update(usermap)
|
self.usermap.update(usermap)
|
||||||
results = [
|
results = [
|
||||||
thread for thread in threads
|
thread for thread in threads
|
||||||
@ -1155,10 +1172,10 @@ class App(object):
|
|||||||
"""
|
"""
|
||||||
self.loop.widget = self.loop.widget[0]
|
self.loop.widget = self.loop.widget[0]
|
||||||
self.loop.stop()
|
self.loop.stop()
|
||||||
call("clear")
|
call("clear", shell=True)
|
||||||
print(welcome)
|
print(welcome)
|
||||||
try:
|
try:
|
||||||
log_in(self.network)
|
log_in(relog=True)
|
||||||
except (KeyboardInterrupt, InterruptedError):
|
except (KeyboardInterrupt, InterruptedError):
|
||||||
pass
|
pass
|
||||||
self.loop.start()
|
self.loop.start()
|
||||||
@ -1171,9 +1188,8 @@ class App(object):
|
|||||||
Options menu callback to anonymize the user and
|
Options menu callback to anonymize the user and
|
||||||
then redisplay the options menu.
|
then redisplay the options menu.
|
||||||
"""
|
"""
|
||||||
self.network.user_name = None
|
network.user_name = network.user_auth = None
|
||||||
self.network.user_auth = None
|
network.user = network("get_me")["data"]
|
||||||
self.network.user = self.network.request("get_me")["data"]
|
|
||||||
self.loop.widget = self.loop.widget[0]
|
self.loop.widget = self.loop.widget[0]
|
||||||
self.set_default_header()
|
self.set_default_header()
|
||||||
self.options_menu()
|
self.options_menu()
|
||||||
@ -1189,7 +1205,7 @@ class App(object):
|
|||||||
urwid.ListBox(
|
urwid.ListBox(
|
||||||
urwid.SimpleFocusListWalker([
|
urwid.SimpleFocusListWalker([
|
||||||
urwid_rainbows(
|
urwid_rainbows(
|
||||||
"This is BBJ, a client/server textboard made for tilde.town!",
|
"This is BBJ, a client/server textboard made for tildes!",
|
||||||
True),
|
True),
|
||||||
urwid.Text(("dim", "...by ~desvox")),
|
urwid.Text(("dim", "...by ~desvox")),
|
||||||
urwid.Divider(self.theme["divider"]),
|
urwid.Divider(self.theme["divider"]),
|
||||||
@ -1215,7 +1231,7 @@ class App(object):
|
|||||||
"""
|
"""
|
||||||
# we can "recycle" the server's formatting abilities to
|
# we can "recycle" the server's formatting abilities to
|
||||||
# use the same syntax for the help text itself
|
# use the same syntax for the help text itself
|
||||||
message = self.network.fake_message(
|
message = network.fake_message(
|
||||||
"\n\n".join(format_help), format="sequential")
|
"\n\n".join(format_help), format="sequential")
|
||||||
|
|
||||||
widget = OptionsMenu(
|
widget = OptionsMenu(
|
||||||
@ -1237,7 +1253,7 @@ class App(object):
|
|||||||
def set_color(self, button, value, color):
|
def set_color(self, button, value, color):
|
||||||
if value == False:
|
if value == False:
|
||||||
return
|
return
|
||||||
self.network.user_update(color=color)
|
network.user_update(color=color)
|
||||||
|
|
||||||
|
|
||||||
def toggle_exit(self, button, value):
|
def toggle_exit(self, button, value):
|
||||||
@ -1264,10 +1280,10 @@ class App(object):
|
|||||||
|
|
||||||
def change_username(self, *_):
|
def change_username(self, *_):
|
||||||
self.loop.stop()
|
self.loop.stop()
|
||||||
call("clear")
|
call("clear", shell=True)
|
||||||
try:
|
try:
|
||||||
name = nameloop(self.network, "Choose a new username")
|
name = nameloop("Choose a new username", True)
|
||||||
self.network.user_update(user_name=name)
|
network.user_update(user_name=name)
|
||||||
motherfucking_rainbows("~~hello there %s~~" % name)
|
motherfucking_rainbows("~~hello there %s~~" % name)
|
||||||
sleep(0.8)
|
sleep(0.8)
|
||||||
self.loop.start()
|
self.loop.start()
|
||||||
@ -1280,10 +1296,10 @@ class App(object):
|
|||||||
|
|
||||||
def change_password(self, *_):
|
def change_password(self, *_):
|
||||||
self.loop.stop()
|
self.loop.stop()
|
||||||
call("clear")
|
call("clear", shell=True)
|
||||||
try:
|
try:
|
||||||
password = password_loop("Choose a new password. Can be empty")
|
password = password_loop("Choose a new password. Can be empty", True)
|
||||||
self.network.user_update(auth_hash=self.network._hash(password))
|
network.user_update(auth_hash=network._hash(password))
|
||||||
motherfucking_rainbows("SET NEW PASSWORD")
|
motherfucking_rainbows("SET NEW PASSWORD")
|
||||||
sleep(0.8)
|
sleep(0.8)
|
||||||
self.loop.start()
|
self.loop.start()
|
||||||
@ -1379,8 +1395,8 @@ class App(object):
|
|||||||
editor_buttons = []
|
editor_buttons = []
|
||||||
edit_mode = []
|
edit_mode = []
|
||||||
|
|
||||||
if self.network.user_auth:
|
if network.user_auth:
|
||||||
account_message = "Logged in as %s." % self.network.user_name
|
account_message = "Logged in as %s." % network.user_name
|
||||||
account_stuff = [
|
account_stuff = [
|
||||||
urwid.Button("Relog", on_press=self.relog),
|
urwid.Button("Relog", on_press=self.relog),
|
||||||
urwid.Button("Go anonymous", on_press=self.unlog),
|
urwid.Button("Go anonymous", on_press=self.unlog),
|
||||||
@ -1397,7 +1413,7 @@ class App(object):
|
|||||||
for index, color in enumerate(colornames):
|
for index, color in enumerate(colornames):
|
||||||
urwid.RadioButton(
|
urwid.RadioButton(
|
||||||
user_colors, color.title(),
|
user_colors, color.title(),
|
||||||
self.network.user["color"] == index,
|
network.user["color"] == index,
|
||||||
self.set_color, index)
|
self.set_color, index)
|
||||||
|
|
||||||
for item in user_colors:
|
for item in user_colors:
|
||||||
@ -1602,9 +1618,7 @@ class App(object):
|
|||||||
descriptor, path = tempfile.mkstemp()
|
descriptor, path = tempfile.mkstemp()
|
||||||
with open(path, "w") as _:
|
with open(path, "w") as _:
|
||||||
_.write(init_body)
|
_.write(init_body)
|
||||||
env = os.environ.copy()
|
call("export LANG=en_US.UTF-8; %s %s" % (self.prefs["editor"], path), shell=True)
|
||||||
env['LANG'] = 'en_US.UTF-8'
|
|
||||||
call("%s %s" % (self.prefs["editor"], shlex.quote(path)), env=env, shell=True)
|
|
||||||
with open(path) as _:
|
with open(path) as _:
|
||||||
body = _.read()
|
body = _.read()
|
||||||
os.remove(path)
|
os.remove(path)
|
||||||
@ -1621,7 +1635,7 @@ class App(object):
|
|||||||
return self.footer_prompt("Title", self.compose)
|
return self.footer_prompt("Title", self.compose)
|
||||||
|
|
||||||
elif title:
|
elif title:
|
||||||
try: self.network.validate("title", title)
|
try: network.validate("title", title)
|
||||||
except AssertionError as e:
|
except AssertionError as e:
|
||||||
return self.footer_prompt(
|
return self.footer_prompt(
|
||||||
"Title", self.compose, extra_text=e.description)
|
"Title", self.compose, extra_text=e.description)
|
||||||
@ -1630,19 +1644,24 @@ class App(object):
|
|||||||
body = self.overthrow_ext_edit(init_body)
|
body = self.overthrow_ext_edit(init_body)
|
||||||
if not body or re.search("^>>[0-9]+$", body):
|
if not body or re.search("^>>[0-9]+$", body):
|
||||||
return self.temp_footer_message("EMPTY POST DISCARDED")
|
return self.temp_footer_message("EMPTY POST DISCARDED")
|
||||||
|
params = {"body": body}
|
||||||
|
|
||||||
if self.mode == "thread" and not edit:
|
if self.mode == "thread" and not edit:
|
||||||
self.network.thread_reply(self.thread["thread_id"], body)
|
endpoint = "thread_reply"
|
||||||
|
params.update({"thread_id": self.thread["thread_id"]})
|
||||||
|
|
||||||
elif edit:
|
elif edit:
|
||||||
self.network.edit_message(
|
endpoint = "edit_post"
|
||||||
thread_id=self.thread["thread_id"],
|
params.update({
|
||||||
post_id=edit["post_id"],
|
"thread_id": self.thread["thread_id"],
|
||||||
body=body)
|
"post_id": edit["post_id"]
|
||||||
|
})
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.network.thread_create(title, body)
|
endpoint = "thread_create"
|
||||||
|
params.update({"title": title})
|
||||||
|
|
||||||
|
network.request(endpoint, **params)
|
||||||
self.refresh()
|
self.refresh()
|
||||||
if edit:
|
if edit:
|
||||||
self.goto_post(edit["post_id"])
|
self.goto_post(edit["post_id"])
|
||||||
@ -1695,12 +1714,6 @@ class App(object):
|
|||||||
self.window_split=True
|
self.window_split=True
|
||||||
self.switch_editor()
|
self.switch_editor()
|
||||||
|
|
||||||
def repaint_screen(self):
|
|
||||||
"""
|
|
||||||
Force urwid to repaint the whole screen.
|
|
||||||
"""
|
|
||||||
self.loop.screen.clear()
|
|
||||||
|
|
||||||
|
|
||||||
class MessageBody(urwid.Text):
|
class MessageBody(urwid.Text):
|
||||||
"""
|
"""
|
||||||
@ -1757,7 +1770,7 @@ class MessageBody(urwid.Text):
|
|||||||
if _c != 0:
|
if _c != 0:
|
||||||
color = str(_c)
|
color = str(_c)
|
||||||
|
|
||||||
if user != "anonymous" and user["user_name"] == app.network.user_name:
|
if user != "anonymous" and user["user_name"] == network.user_name:
|
||||||
display = "[You]"
|
display = "[You]"
|
||||||
# bold it
|
# bold it
|
||||||
color += "0"
|
color += "0"
|
||||||
@ -1965,7 +1978,7 @@ class ExternalEditor(urwid.Terminal):
|
|||||||
# should use the options menu to switch to Overthrow mode.
|
# should use the options menu to switch to Overthrow mode.
|
||||||
env.update({"LANG": "POSIX"})
|
env.update({"LANG": "POSIX"})
|
||||||
command = ["bash", "-c", "{} {}; echo Press any key to kill this window...".format(
|
command = ["bash", "-c", "{} {}; echo Press any key to kill this window...".format(
|
||||||
app.prefs["editor"], shlex.quote(self.path))]
|
app.prefs["editor"], self.path)]
|
||||||
super(ExternalEditor, self).__init__(command, env, app.loop, app.prefs["edit_escapes"]["abort"])
|
super(ExternalEditor, self).__init__(command, env, app.loop, app.prefs["edit_escapes"]["abort"])
|
||||||
urwid.connect_signal(self, "closed", self.exterminate)
|
urwid.connect_signal(self, "closed", self.exterminate)
|
||||||
|
|
||||||
@ -1974,7 +1987,7 @@ class ExternalEditor(urwid.Terminal):
|
|||||||
# app.loop.widget = app.loop.widget[0]
|
# app.loop.widget = app.loop.widget[0]
|
||||||
# if not value:
|
# if not value:
|
||||||
# app.loop.stop()
|
# app.loop.stop()
|
||||||
# call("clear")
|
# call("clear", shell=True)
|
||||||
# print(welcome)
|
# print(welcome)
|
||||||
# log_in(True)
|
# log_in(True)
|
||||||
# app.loop.start()
|
# app.loop.start()
|
||||||
@ -1982,21 +1995,9 @@ class ExternalEditor(urwid.Terminal):
|
|||||||
|
|
||||||
|
|
||||||
def exterminate(self, *_, anon_confirmed=False):
|
def exterminate(self, *_, anon_confirmed=False):
|
||||||
# close the editor and grab the post body
|
|
||||||
app.close_editor()
|
|
||||||
with open(self.path) as _:
|
|
||||||
body = _.read().strip()
|
|
||||||
os.remove(self.path)
|
|
||||||
|
|
||||||
# make sure its not empty
|
|
||||||
if not body or re.search("^>>[0-9]+$", body):
|
|
||||||
app.temp_footer_message("EMPTY POST DISCARDED")
|
|
||||||
return
|
|
||||||
|
|
||||||
# are we anonymous? check if the user wants to log in first
|
|
||||||
if app.prefs["confirm_anon"] \
|
if app.prefs["confirm_anon"] \
|
||||||
and not anon_confirmed \
|
and not anon_confirmed \
|
||||||
and app.network.user["user_name"] == "anonymous":
|
and network.user["user_name"] == "anonymous":
|
||||||
# TODO fixoverlay: urwid terminal widgets have been mucking
|
# TODO fixoverlay: urwid terminal widgets have been mucking
|
||||||
# up overlay dialogs since the wee days of bbj, i really
|
# up overlay dialogs since the wee days of bbj, i really
|
||||||
# need to find a real solution instead of dodging the issue
|
# need to find a real solution instead of dodging the issue
|
||||||
@ -2023,7 +2024,7 @@ class ExternalEditor(urwid.Terminal):
|
|||||||
# return
|
# return
|
||||||
# else:
|
# else:
|
||||||
app.loop.stop()
|
app.loop.stop()
|
||||||
call("clear")
|
call("clear", shell=True)
|
||||||
print(anon_warn)
|
print(anon_warn)
|
||||||
choice = paren_prompt(
|
choice = paren_prompt(
|
||||||
"Post anonymously?", default="yes", choices=["Yes", "no"]
|
"Post anonymously?", default="yes", choices=["Yes", "no"]
|
||||||
@ -2032,20 +2033,27 @@ class ExternalEditor(urwid.Terminal):
|
|||||||
log_in(True)
|
log_in(True)
|
||||||
app.loop.start()
|
app.loop.start()
|
||||||
|
|
||||||
# ok; do the post
|
app.close_editor()
|
||||||
self.params.update({"body": body})
|
with open(self.path) as _:
|
||||||
app.network.request(self.endpoint, **self.params)
|
body = _.read().strip()
|
||||||
if self.endpoint == "edit_post":
|
os.remove(self.path)
|
||||||
app.refresh()
|
|
||||||
app.goto_post(self.params["post_id"])
|
|
||||||
|
|
||||||
elif app.mode == "thread":
|
if body and not re.search("^>>[0-9]+$", body):
|
||||||
app.refresh()
|
self.params.update({"body": body})
|
||||||
app.goto_post(app.thread["reply_count"])
|
network.request(self.endpoint, **self.params)
|
||||||
|
if self.endpoint == "edit_post":
|
||||||
|
app.refresh()
|
||||||
|
app.goto_post(self.params["post_id"])
|
||||||
|
|
||||||
|
elif app.mode == "thread":
|
||||||
|
app.refresh()
|
||||||
|
app.goto_post(app.thread["reply_count"])
|
||||||
|
|
||||||
|
else:
|
||||||
|
app.last_pos = None
|
||||||
|
app.index()
|
||||||
else:
|
else:
|
||||||
app.last_pos = None
|
app.temp_footer_message("EMPTY POST DISCARDED")
|
||||||
app.index()
|
|
||||||
|
|
||||||
|
|
||||||
def keypress(self, size, key):
|
def keypress(self, size, key):
|
||||||
@ -2063,7 +2071,7 @@ class ExternalEditor(urwid.Terminal):
|
|||||||
|
|
||||||
if keyl == "ctrl l":
|
if keyl == "ctrl l":
|
||||||
# always do this, and also pass it to the terminal
|
# always do this, and also pass it to the terminal
|
||||||
app.repaint_screen()
|
wipe_screen()
|
||||||
|
|
||||||
elif key == app.prefs["edit_escapes"]["abort"]:
|
elif key == app.prefs["edit_escapes"]["abort"]:
|
||||||
self.terminate()
|
self.terminate()
|
||||||
@ -2141,7 +2149,7 @@ class OptionsMenu(urwid.LineBox):
|
|||||||
return self.keypress(size, "enter")
|
return self.keypress(size, "enter")
|
||||||
|
|
||||||
elif keyl == "ctrl l":
|
elif keyl == "ctrl l":
|
||||||
app.repaint_screen()
|
wipe_screen()
|
||||||
|
|
||||||
|
|
||||||
def mouse_event(self, size, event, button, x, y, focus):
|
def mouse_event(self, size, event, button, x, y, focus):
|
||||||
@ -2197,7 +2205,7 @@ class ActionBox(urwid.ListBox):
|
|||||||
self.change_focus(size, 0)
|
self.change_focus(size, 0)
|
||||||
|
|
||||||
elif key == "ctrl l":
|
elif key == "ctrl l":
|
||||||
app.repaint_screen()
|
wipe_screen()
|
||||||
|
|
||||||
elif keyl == "o":
|
elif keyl == "o":
|
||||||
app.options_menu()
|
app.options_menu()
|
||||||
@ -2244,13 +2252,13 @@ class ActionBox(urwid.ListBox):
|
|||||||
elif key == "~":
|
elif key == "~":
|
||||||
# sssssshhhhhhhh
|
# sssssshhhhhhhh
|
||||||
app.loop.stop()
|
app.loop.stop()
|
||||||
try: call("sl")
|
try: call("sl", shell=True)
|
||||||
except: pass
|
except: pass
|
||||||
app.loop.start()
|
app.loop.start()
|
||||||
|
|
||||||
elif keyl == "$":
|
elif keyl == "$":
|
||||||
app.loop.stop()
|
app.loop.stop()
|
||||||
call("clear")
|
call("clear", shell=True)
|
||||||
readline.set_completer(rlcompleter.Completer().complete)
|
readline.set_completer(rlcompleter.Completer().complete)
|
||||||
readline.parse_and_bind("tab: complete")
|
readline.parse_and_bind("tab: complete")
|
||||||
interact(banner="Python " + version + "\nBBJ Interactive Console\nCtrl-D exits.", local=globals())
|
interact(banner="Python " + version + "\nBBJ Interactive Console\nCtrl-D exits.", local=globals())
|
||||||
@ -2298,7 +2306,7 @@ def frilly_exit():
|
|||||||
out = " ~~CoMeE BaCkK SooOn~~ 0000000"
|
out = " ~~CoMeE BaCkK SooOn~~ 0000000"
|
||||||
motherfucking_rainbows(out.zfill(width))
|
motherfucking_rainbows(out.zfill(width))
|
||||||
else:
|
else:
|
||||||
call("clear")
|
call("clear", shell=True)
|
||||||
motherfucking_rainbows("Come back soon! <3")
|
motherfucking_rainbows("Come back soon! <3")
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
@ -2377,57 +2385,47 @@ def paren_prompt(text, positive=True, choices=[], function=input, default=None):
|
|||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
def sane_value(prompt, validate, positive=True, function=input):
|
def sane_value(key, prompt, positive=True, return_empty=False):
|
||||||
"""Prompts for an input with paren_prompt until validate(response)
|
response = paren_prompt(prompt, positive)
|
||||||
returns None (or something falsy). Otherwise the returned string is used
|
if return_empty and response == "":
|
||||||
as the new prompt.
|
return response
|
||||||
"""
|
try: network.validate(key, response)
|
||||||
while 1:
|
except AssertionError as e:
|
||||||
response = paren_prompt(prompt, positive, function=function)
|
return sane_value(key, e.description, False)
|
||||||
error = validate(response)
|
return response
|
||||||
if not error:
|
|
||||||
return response
|
|
||||||
prompt = str(error) if error != None else ""
|
|
||||||
positive = False
|
|
||||||
|
|
||||||
def password_loop(prompt, positive=True):
|
def password_loop(prompt, positive=True):
|
||||||
while 1:
|
response1 = paren_prompt(prompt, positive, function=getpass)
|
||||||
response1 = paren_prompt(prompt, positive, function=getpass)
|
if response1 == "":
|
||||||
if response1 == "":
|
confprompt = "Confirm empty password"
|
||||||
confprompt = "Confirm empty password"
|
else:
|
||||||
else:
|
confprompt = "Confirm it"
|
||||||
confprompt = "Confirm it"
|
response2 = paren_prompt(confprompt, function=getpass)
|
||||||
response2 = paren_prompt(confprompt, function=getpass)
|
if response1 != response2:
|
||||||
if response1 != response2:
|
return password_loop("Those didnt match. Try again", False)
|
||||||
prompt = "Those didnt match. Try again"
|
return response1
|
||||||
positive = False
|
|
||||||
else:
|
|
||||||
return response1
|
|
||||||
|
|
||||||
|
|
||||||
def nameloop(network, prompt, positive=True):
|
def nameloop(prompt, positive):
|
||||||
def validate_name(name):
|
name = sane_value("user_name", prompt, positive)
|
||||||
try: network.validate("user_name", name)
|
if network.user_is_registered(name):
|
||||||
except AssertionError as e:
|
return nameloop("%s is already registered" % name, False)
|
||||||
return e.description
|
return name
|
||||||
if network.user_is_registered(name):
|
|
||||||
return "%s is already registered" % name
|
|
||||||
return sane_value(prompt, validate_name, positive)
|
|
||||||
|
|
||||||
def log_in(network, name="", password=""):
|
|
||||||
|
def log_in(relog=False):
|
||||||
"""
|
"""
|
||||||
Handles login or registration. If name and/or password are not
|
Handles login or registration using an oldschool input()
|
||||||
provided, the user is prompted for them using an oldschool
|
chain. The user is run through this before starting the
|
||||||
input() chain. The user is run through this before starting the
|
|
||||||
curses app.
|
curses app.
|
||||||
"""
|
"""
|
||||||
if not name:
|
if relog:
|
||||||
def validate_name(response):
|
name = sane_value("user_name", "Username", return_empty=True)
|
||||||
if response != "": # allow empty username
|
else:
|
||||||
try: network.validate("user_name", response)
|
name = get_arg("user") \
|
||||||
except AssertionError as e:
|
or os.getenv("BBJ_USER") \
|
||||||
return e.description
|
or sane_value("user_name", "Username", return_empty=True)
|
||||||
name = sane_value("Username", validate_name)
|
|
||||||
if name == "":
|
if name == "":
|
||||||
motherfucking_rainbows("~~W3 4R3 4n0nYm0u5~~")
|
motherfucking_rainbows("~~W3 4R3 4n0nYm0u5~~")
|
||||||
else:
|
else:
|
||||||
@ -2436,18 +2434,21 @@ def log_in(network, name="", password=""):
|
|||||||
try:
|
try:
|
||||||
network.set_credentials(
|
network.set_credentials(
|
||||||
name,
|
name,
|
||||||
password if name and password else ""
|
os.getenv("BBJ_PASSWORD", default="")
|
||||||
|
if not relog else ""
|
||||||
)
|
)
|
||||||
# make it easy for people who use an empty password =)
|
# make it easy for people who use an empty password =)
|
||||||
motherfucking_rainbows("~~welcome back {}~~".format(network.user_name))
|
motherfucking_rainbows("~~welcome back {}~~".format(network.user_name))
|
||||||
|
|
||||||
except ConnectionRefusedError:
|
except ConnectionRefusedError:
|
||||||
def validate_creds(password):
|
def login_loop(prompt, positive):
|
||||||
try:
|
try:
|
||||||
|
password = paren_prompt(prompt, positive, function=getpass)
|
||||||
network.set_credentials(name, password)
|
network.set_credentials(name, password)
|
||||||
except ConnectionRefusedError:
|
except ConnectionRefusedError:
|
||||||
return "// R E J E C T E D //."
|
login_loop("// R E J E C T E D //.", False)
|
||||||
password = sane_value("Enter your password", validate_creds, function=getpass)
|
|
||||||
|
login_loop("Enter your password", True)
|
||||||
motherfucking_rainbows("~~welcome back {}~~".format(network.user_name))
|
motherfucking_rainbows("~~welcome back {}~~".format(network.user_name))
|
||||||
|
|
||||||
except ValueError:
|
except ValueError:
|
||||||
@ -2458,7 +2459,7 @@ def log_in(network, name="", password=""):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if response == "c":
|
if response == "c":
|
||||||
name = nameloop(network, "Pick a new name")
|
name = nameloop("Pick a new name", True)
|
||||||
|
|
||||||
elif response == "n":
|
elif response == "n":
|
||||||
raise InterruptedError
|
raise InterruptedError
|
||||||
@ -2561,39 +2562,25 @@ def ignore(*_, **__):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
# XxX_N0_4rgP4rs3_XxX ###yoloswag
|
def wipe_screen(*_):
|
||||||
def get_arg(key, default=None, get_value=True):
|
"""
|
||||||
try:
|
A crude hack to repaint the whole screen. I didnt immediately
|
||||||
spec = argv.index("--" + key)
|
see anything to acheive this in the MainLoop methods so this
|
||||||
value = argv[spec + 1] if get_value else True
|
will do, I suppose.
|
||||||
except ValueError: # --key not specified
|
"""
|
||||||
value = default
|
app.loop.stop()
|
||||||
except IndexError: # flag given but no value
|
call("clear", shell=True)
|
||||||
exit("invalid format for --" + key)
|
app.loop.start()
|
||||||
return value
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if get_arg("help", False, False):
|
|
||||||
print(help_text)
|
|
||||||
exit()
|
|
||||||
|
|
||||||
try:
|
|
||||||
network = BBJ(get_arg("host", "127.0.0.1"),
|
|
||||||
get_arg("port", 7099),
|
|
||||||
get_arg("https", False, False))
|
|
||||||
except URLError as e:
|
|
||||||
# print the connection error in red
|
|
||||||
exit("\033[0;31m%s\033[0m" % repr(e))
|
|
||||||
|
|
||||||
global app
|
global app
|
||||||
app = App(network)
|
app = App()
|
||||||
call("clear")
|
call("clear", shell=True)
|
||||||
motherfucking_rainbows(obnoxious_logo)
|
motherfucking_rainbows(obnoxious_logo)
|
||||||
print(welcome)
|
print(welcome)
|
||||||
try:
|
try:
|
||||||
name = get_arg("user") or os.getenv("BBJ_USER")
|
log_in()
|
||||||
password = os.getenv("BBJ_PASSWORD", default="")
|
|
||||||
log_in(network, name, password)
|
|
||||||
app.index()
|
app.index()
|
||||||
app.loop.run()
|
app.loop.run()
|
||||||
except (InterruptedError, KeyboardInterrupt):
|
except (InterruptedError, KeyboardInterrupt):
|
||||||
|
@ -2,6 +2,6 @@
|
|||||||
"port": 7099,
|
"port": 7099,
|
||||||
"host": "127.0.0.1",
|
"host": "127.0.0.1",
|
||||||
"instance_name": "BBJ",
|
"instance_name": "BBJ",
|
||||||
"allow_anon": True,
|
"allow_anon": true,
|
||||||
"debug": False
|
"debug": false
|
||||||
}
|
}
|
||||||
|
1
docs/_config.yml
Normal file
1
docs/_config.yml
Normal file
@ -0,0 +1 @@
|
|||||||
|
theme: jekyll-theme-midnight
|
17
setup.sh
17
setup.sh
@ -15,20 +15,29 @@ It takes the following flags:
|
|||||||
|
|
||||||
You can optionally pass a different python interpreter to use (such as
|
You can optionally pass a different python interpreter to use (such as
|
||||||
a virtual environment), with no arguments this will use the system python3
|
a virtual environment), with no arguments this will use the system python3
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
exit;;
|
exit;;
|
||||||
|
|
||||||
--dbset )
|
--dbset )
|
||||||
sqlite3 data.sqlite < schema.sql
|
sqlite3 data.sqlite < schema.sql
|
||||||
echo cleared
|
echo cleared
|
||||||
chmod 600 data.sqlite
|
chmod 600 data.sqlite
|
||||||
exit;;
|
exit;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
PYTHON=`which python3`
|
|
||||||
[[ -e logs ]] || mkdir logs; mkdir logs/exceptions
|
[[ -e logs ]] || mkdir logs; mkdir logs/exceptions
|
||||||
|
|
||||||
|
PYTHON=`which python3`
|
||||||
[[ -z $1 ]] || PYTHON=$1
|
[[ -z $1 ]] || PYTHON=$1
|
||||||
echo Using $PYTHON...
|
echo Using $PYTHON...
|
||||||
$PYTHON -m pip install ${DEPS[*]}
|
$PYTHON -m pip install ${DEPS[*]}
|
||||||
|
|
||||||
echo "Enter [i] to initialize a new database"
|
echo "Enter [i] to initialize a new database"
|
||||||
read CLEAR
|
read CLEAR
|
||||||
[[ $CLEAR == "i" ]] && sqlite3 data.sqlite < schema.sql; chmod 600 data.sqlite
|
|
||||||
|
if [[ $CLEAR == "i" ]]; then
|
||||||
|
sqlite3 data.sqlite < schema.sql
|
||||||
|
chmod 600 data.sqlite
|
||||||
|
fi
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user