فهرست منبع

Implement spam reduction for appraisals, and add self-like and ownership flags

Kirk Trombley 3 سال پیش
والد
کامیت
4e5d57ce66
1فایلهای تغییر یافته به همراه24 افزوده شده و 8 حذف شده
  1. 24 8
      commands/commands/rollcoin.py

+ 24 - 8
commands/commands/rollcoin.py

@@ -7,8 +7,8 @@ import asyncio
 
 from sudoku_py import SudokuGenerator, Sudoku
 
-from rollbot import as_command, initialize_data, RollbotFailure, Attachment
-from rollbot.injection import Data, Sender, Config, Const, Arg, Reply, OriginAdmin, Args, Attachments, Origin, Request, Lazy
+from rollbot import as_command, initialize_data, RollbotFailure, Attachment, Response
+from rollbot.injection import Data, Sender, Config, Const, Arg, Reply, OriginAdmin, Args, Attachments, Origin, Request, Lazy, Channel, SenderName
 
 # View
 #   !wallet - shows your number of rollcoins, NFTs (Non-Functional Tamagotchis), and market balance
@@ -106,6 +106,9 @@ MarketTransitions = Config("rollcoin.market.transitions")
 MarketMultipliers = Config("rollcoin.market.multipliers")
 MarketMessages = Config("rollcoin.market.messages")
 NameAPIKey = Config("rollcoin.gacha.name_api_key")
+AppraiseChannel = Config("rollcoin.appraise.channel")
+AppraiseAllowSelfLike = Config("rollcoin.appraise.allow_self")
+AppraiseRequireOwnership = Config("rollcoin.appraise.require_own")
 
 
 @as_command
@@ -420,33 +423,46 @@ async def appraise(
     origin: Origin,
     attachments: Attachments,
     sender_id: Sender,
+    sender_name: SenderName,
     get_sender_wallet: Lazy(SenderWallet),
     wallet_store: Data(RollcoinWallet),
     state: State,
     state_store: Data(RollcoinState),
-    reply: Reply,
+    received_channel: Channel,
+    appraise_channel: AppraiseChannel,
+    allow_self_likes: AppraiseAllowSelfLike,
+    require_ownership: AppraiseRequireOwnership,
 ):
     """
     Use this command while replying to a popular post, and I will purchase it for some RollCoins!
     """
+    def make_response(text):
+        return Response(
+            origin_id=origin, 
+            channel_id=appraise_channel or received_channel,
+            text=text,
+        )
+
     if origin == "GROUPME":
         try:
             reply_attachment = next(a for a in attachments if a.name == "reply")
             target_msg = json.loads(await reply_attachment.body())
-            appraisal_id = f"GROUPME-{target_msg['group_id']}-{target_msg['id']}"
-            score_base = len(target_msg["favorited_by"])
         except:
             logger.exception("Failed appraisal, logging for debugging")
             RollbotFailure.INVALID_ARGUMENTS.raise_exc("Reply to a message to have it appraised, I could not read that one")
+        appraisal_id = f"GROUPME-{target_msg['group_id']}-{target_msg['id']}"
+        if require_ownership and target_msg["sender_id"] != sender_id:
+            RollbotFailure.INVALID_ARGUMENTS.raise_exc("You can only appraise your own posts!")
+        score_base = len([t for t in target_msg["favorited_by"] if allow_self_likes or t != target_msg["sender_id"]])
     # other origins an be handled here
     else:
         RollbotFailure.INVALID_COMMAND.raise_exc(f"Message appraisal is not implemented in this platform (origin was {origin})")
 
     if appraisal_id in state.appraised:
-        return "Sorry, I've already purchased that message!", reply
+        return make_response(f"Sorry {sender_name}, I've already purchased that message!")
 
     if score_base <= 2:
-        return "Sorry, I don't think that message is worth very much...", reply
+        return make_response(f"Sorry {sender_name}, I don't think that message is worth very much...")
 
     value = round(abs(random.gauss(score_base * 50, 15)), 2)
     sender_wallet = await get_sender_wallet()
@@ -455,7 +471,7 @@ async def appraise(
     state.appraised.append(appraisal_id)
     await state_store.save(GLOBAL_STATE_KEY, state)
 
-    return f"That post is very interesting! I will purchase it for {value} RollCoins! That brings your balance to {sender_wallet.balance}", reply
+    return make_response(f"That post is very interesting, {sender_name}!\nI will purchase it for {value} RollCoins!\nThat brings your balance to {sender_wallet.balance}")
 
 
 def pull_gacha_color():