def message_of_the_day(args, guild, v): """Set or clear a Message of the Day, to be shown to users upon joining this channel. Messages are shown as being spoken by the guild. (Must be Guildmaster.)""" if len(args) >= 2: message = " ".join(args[1:]) message = preprocess(message) with CustomRenderer() as renderer: message = renderer.render(mistletoe.Document(message)) message = sanitize(message, linkgen=True) guild.motd = message g.db.add(guild) g.db.commit() send("Message updated") data = { "avatar": guild.profile_url, "username": guild.name, "text": guild.motd, "room": guild.fullname, "guild": guild.name, "time": now() } emit('motd', data, to=request.sid) else: guild.motd = '' g.db.add(guild) g.db.commit() send("Message removed")
def speak(text, user, guild, as_guild=False): if isinstance(text, list): text = " ".join(text) text = preprocess(text) with CustomRenderer() as renderer: text = renderer.render(mistletoe.Document(text)) text = sanitize(text, linkgen=True) if as_guild: data = { "avatar": guild.profile_url, "username": guild.name, "text": text, "room": guild.fullname, "guild": guild.name, "time": now() } emit("motd", data, to=guild.fullname) else: data = { "avatar": user.profile_url, "username": user.username, "text": text, "room": guild.fullname, "guild": guild.name, "time": now() } if request.headers.get("X-User-Type") == "Bot": emit("bot", data, to=guild.fullname) else: emit("speak", data, to=guild.fullname) return
def wallop(args, guild, v): """Send a global broadcast. (Must be site administrator.)""" text = " ".join(args[1:]) if not text: return text = preprocess(text) with CustomRenderer() as renderer: text = renderer.render(mistletoe.Document(text)) text = sanitize(text, linkgen=True) ban = screen(text) if ban: speak_help(f"Unable to send message - banned domain {ban}") return data = { "avatar": v.profile_url, "username": v.username, "text": text, "time": now(), "userlink": v.permalink } sent = [] for uid in SIDS: for sid in SIDS[uid]: for roomid in rooms(sid=sid): if roomid.startswith('t4_') and roomid not in sent: emit('wallop', data, to=roomid) sent.append(roomid)
def message_of_the_day(args, guild, v): """Set or clear a Message of the Day, to be shown to users upon joining this channel. Messages are shown as being spoken by the guild. (Must be Guildmaster.)""" if len(args) >= 2: message = " ".join(args[1:]) message = preprocess(message) with CustomRenderer() as renderer: message = renderer.render(mistletoe.Document(message)) message = sanitize(message, linkgen=True) ban = screen(message) if ban: speak_help(f"Unable to send message - banned domain {ban}") return guild.motd = message g.db.add(guild) g.db.commit() speak_help(f"Welcome message updated to:") speak(guild.motd, v, guild, event='motd', to=request.sid) else: guild.motd = '' g.db.add(guild) g.db.commit() send("Message removed")
def direct_message(args, guild, v): """Send someone a private message. Use Tab to reply to the most recent private message""" if len(args) < 3: send("Not enough arguments. Type `/help msg` for more information.") return user = get_user(args[1], graceful=True) if not user: send(f"No user named @{args[1]}.") return targets = SIDS.get(user.id, []) if (not targets) or v.any_block_exists(user): speak_help(f"@{user.username} is not online right now.") return text = " ".join(args[2:]) text = preprocess(text) with CustomRenderer() as renderer: text = renderer.render(mistletoe.Document(text)) text = sanitize(text, linkgen=True) ban = screen(text) if ban: speak_help(f"Unable to send message - banned domain {ban}") return t = now() data = { "avatar": v.profile_url, "username": v.username, "text": text, "time": t, "userlink": v.permalink } for sid in targets: emit('msg-in', data, to=sid) data = { "avatar": v.profile_url, "username": user.username, "text": text, "time": t, "userlink": user.permalink } for sid in SIDS.get(v.id, []): emit('msg-out', data, to=sid)
def say_guild(args, guild, v): """Say something as the Guild. (Must be Guildmaster.)""" text = " ".join(args[1:]) text = preprocess(text) with CustomRenderer() as renderer: text = renderer.render(mistletoe.Document(text)) text = sanitize(text, linkgen=True) data = { "avatar": guild.profile_url, "username": guild.name, "text": text, "time": now() } emit('motd', data, to=guild.fullname)
def speak(text, user, guild, as_guild=False, event="speak", to=None): if isinstance(text, list): text = " ".join(text) text = preprocess(text) with CustomRenderer() as renderer: text = renderer.render(mistletoe.Document(text)) text = sanitize(text, linkgen=True) to = to or guild.fullname ban = screen(text) if ban: speak_help(f"Unable to send message - banned domain {ban}") return if as_guild or event == "motd": data = { "avatar": guild.profile_url, "username": guild.name, "text": text, "room": guild.fullname, "guild": guild.name, "time": now(), 'userlink': guild.permalink } emit("motd", data, to=to) else: data = { "avatar": user.profile_url, "username": user.username, "text": text, "room": guild.fullname, "guild": guild.name, "time": now(), "userlink": user.permalink } if request.headers.get("X-User-Type", "").lower() == "bot": emit("bot", data, to=to) else: emit(event, data, to=to) return
def speak_as_gm(args, guild, v): """Distinguish your message with a Guildmaster's crown. (Must be Guildmaster.)""" text = " ".join(args[1:]) if not text: return text = preprocess(text) with CustomRenderer() as renderer: text = renderer.render(mistletoe.Document(text)) text = sanitize(text, linkgen=True) data = { "avatar": v.profile_url, "username": v.username, "text": text, "room": guild.fullname, "guild": guild.name, "time": now() } emit('gm', data, to=guild.fullname)
def speak_admin(args, guild, v): """Distinguish your message with an Administrator's shield. (Must be site administrator.)""" text = " ".join(args[1:]) if not text: return text = preprocess(text) with CustomRenderer() as renderer: text = renderer.render(mistletoe.Document(text)) text = sanitize(text, linkgen=True) data = { "avatar": v.profile_url, "username": v.username, "text": text, 'guild': guild.name, 'room': guild.fullname, "time": now() } emit('admin', data, to=guild.fullname)
def dmca_post(v): data = {x: request.form[x] for x in request.form if x != "formkey"} email_text = render_template("help/dmca_email.md", v=v, **data) with CustomRenderer() as renderer: email_html = renderer.render(mistletoe.Document(email_text)) email_html = sanitize(email_html, linkgen=True) try: send_mail(environ.get("admin_email"), "DMCA Takedown Request", email_html) except BaseException: return render_template( "/help/dmca.html", error="Unable to save your request. Please try again later.", v=v) post_text = render_template("help/dmca_notice.md", v=v, **data) with CustomRenderer() as renderer: post_html = renderer.render(mistletoe.Document(post_text)) post_html = sanitize(post_html, linkgen=True) # create +RuqqusDMCA post new_post = Submission(author_id=1, domain_ref=None, board_id=1000, original_board_id=1000, over_18=False, post_public=True, repost_id=None, is_offensive=False) g.db.add(new_post) g.db.flush() new_post_aux = SubmissionAux(id=new_post.id, url=None, body=post_text, body_html=post_html, embed_url=None, title=f"DMCA {new_post.base36id}") g.db.add(new_post_aux) g.db.flush() comment_text = f"##### Username\n\n@{v.username}\n\n##### Email\n\n{v.email}\n\n##### Address\n\n{data['your_address']}" with CustomRenderer() as renderer: c_html = renderer.render(mistletoe.Document(comment_text)) c_html = sanitize(c_html, linkgen=True) c = Comment(author_id=1, parent_submission=new_post.id, parent_fullname=new_post.fullname, parent_comment_id=None, level=1, over_18=False, is_nsfl=False, is_op=True, is_offensive=False, original_board_id=1000, deleted_utc=int(time.time())) g.db.add(c) g.db.flush() c_aux = CommentAux(id=c.id, body_html=c_html, body=comment_text) g.db.add(c_aux) g.db.commit() return render_template("/help/dmca.html", msg="Your request has been saved.", v=v)