Closed 3Mstripes closed 4 years ago
Firstly, you have opened a pull request, which is only necessary (or useful) when you have code changes in your Github fork. So I'll be closing this one.
The changes you need to make to relay()
look as follows:
def relay(ev):
# handle commands and karma giving
if ev.content_type == "text" and ev.text.startswith("/"):
pos = ev.text.find(" ") if " " in ev.text else len(ev.text)
c = ev.text[1:pos].lower()
if c in registered_commands.keys():
registered_commands[c](ev)
return
elif ev.content_type == "text" and ev.text.strip() == "+1":
return cmd_plusone(ev)
# filter disallowed media types
if not allow_documents and ev.content_type == "document" and ev.document.mime_type not in ("image/gif", "video/mp4"):
return
c_user = UserContainer(ev.from_user)
user = db.getUser(id=ev.from_user.id)
# find out which message is being replied to
reply_msid = None
if ev.reply_to_message is not None:
reply_msid = ch.lookupMapping(ev.from_user.id, data=ev.reply_to_message.message_id)
if reply_msid is None:
logging.warning("Message replied to not found in cache")
if ev.content_type == "text" and user.tripcodeToggle:
msid = core.send_signed_user_message(c_user, calc_spam_score(ev), ev.text, reply_msid, tripcode=True)
if isinstance(msid, rp.Reply):
return send_answer(ev, msid)
return ch.saveMapping(c_user.id, msid, ev.message_id)
msid = core.prepare_user_message(c_user, calc_spam_score(ev))
if isinstance(msid, rp.Reply): # don't relay message, instead reply with something
return send_answer(ev, msid)
# relay message to all other users
logging.debug("relay(): msid=%d reply_msid=%r", msid, reply_msid)
for user2 in db.iterateUsers():
if not user2.isJoined():
continue
if user2 == user and not user.debugEnabled:
ch.saveMapping(user2.id, msid, ev.message_id)
continue
send_to_single(ev, msid, user2, reply_msid)
I am new to Github so you will have to deal with some terrible formatting
I got tired of using /t or /tsign all the time so I wanted to make a toggle tripcode option
I managed to give the user an option to toggle something to enable and disable tripcode, but I don't know how to implement the tripcode to passively turn their text into a tsigned message, here's what I did
In Telegram.py
Line 41: cmds = [ "start", "stop", "users", "info", "motd", "toggledebug", "togglekarma", "tripcodetoggle",
Line 373 cmd_tripcodetoggle = wrap_core(core.toggle_tripcode)
In
Core.py
Line 292
@requireUser def toggle_tripcode(user): with db.modifyUser(id=user.id) as user: user.tripcodeToggle = not user.tripcodeToggle new = user.tripcodeToggle return rp.Reply(rp.types.BOOLEAN_CONFIG, description="Username (tripcode)", enabled=new)
### database.py
class User():
def init(self): self.tripcodeToggle = None # bool
def defaults(self): self.rank = RANKS.banned # STARTS OUT AS A BANNED USER TO PREVENT UNAUTHROIZED USER FROM READING(EDITED ENTRY) self.joined = datetime.now() self.left = datetime.now() # datetime? (EDITED ENTRY) self.lastActive = datetime.now() # datetime (EDITED ENTRY) self.blacklistReason = "unidentified user" # str? (EDITED ENTRY)
self.lastActive = self.joined self.warnings = 0 self.karma = 0 self.hideKarma = False self.debugEnabled = False self.tripcodeToggle = False
def userToDict(user): props = ["id", "username", "realname", "rank", "joined", "left", "lastActive", "cooldownUntil", "blacklistReason", "warnings", "warnExpiry", "karma", "hideKarma", "debugEnabled", "tripcode", "tripcodeToggle"_]
def userFromDict(d): if d is None: return None props = ["id", "username", "realname", "rank", "blacklistReason", "warnings", "karma", "hideKarma", "debugEnabled", "tripcodeToggle"_]
-CREATE TABLE IF NOT EXISTS
users
(id
BIGINT NOT NULL,username
TEXT,realname
TEXT NOT NULL,rank
INTEGER NOT NULL,joined
TIMESTAMP NOT NULL,left
TIMESTAMP,lastActive
TIMESTAMP NOT NULL,cooldownUntil
TIMESTAMP,blacklistReason
TEXT,warnings
INTEGER NOT NULL,warnExpiry
TIMESTAMP,karma
INTEGER NOT NULL,hideKarma
TINYINT NOT NULL,debugEnabled
TINYINT NOT NULL,tripcode
TEXT, 'tripcodeToggle' TINYINT NOT NULL,Do you think you can add in a passive tripcode toggle function, or give me some pointers?