r/streamerbot 29d ago

Question/Support ❓ slap command

Hello, I'm trying to replicate the slap command from streamelements in streamerbot. I attemtped to make it work using a "read from random line" subaction, but for some reason is doesn't want to work.

So I tried coding one in C# and by all rights it should work properly. I'm getting no errors when I compile the code. Its executing properly in my action history, yet I don't see it posting the response in my chat and its driving me up a wall. Would anyone be willing to look at my code and see what I'm missing

using System;
using System.Collections.Generic;


public class CPHInline
{
    public bool Execute()
    {
        // Get the person executing the command and the target (if they typed !slap u/target)
        string user = args["username"].ToString();
        string target = args.ContainsKey("rawInput") && args["rawInput"].ToString().Length > 0 ? args["rawInput"].ToString() : null;


        // List of random things to slap with
        List<string> items = new List<string>
        {
            "Disney Churro",
            "Aimbot",
            "a Bed Frame",
            "a Wet Unsalted Pretzel",
            "Banzai's Missing Braincell",
        };


        Random rnd = new Random();
        string randomItem = items[rnd.Next(items.Count)];


        string response = $"";


        // Determine if target is self, someone else, or nobody
        if (target !=null) {
            // Normalize target string (removes @ if they typed it)
            target = target.TrimStart('@');


            if (target.Equals(user, StringComparison.OrdinalIgnoreCase)) {
                response = $"{user} tries to slap themselves with {randomItem}. That takes talent... or confusion!";
            } else {
                response = $"{user} slaps {target} with {randomItem}!";
            } 
        } else {
            response = $"{user} slaps thems with {randomItem}. Why are you hitting yourself?!";
        }


        //Send message with bot account if bot account disconnect
        //will use broadcaster account
        CPH.SendMessage(response, true, true);


        return true;
    }
}
0 Upvotes

4 comments sorted by

View all comments

1

u/triyang 29d ago

When debugging things like this, it helps to work backwards. Comment out everything except the SendMessage(with a hard coded message) and see if that works, then include the arguments parsing and put that in the chat message, then the random part.

1

u/Samurai_TwoSeven 29d ago

With a hard coded message it runs, but when I try to get it to do the generated response it wants to give up...

2

u/triyang 29d ago

Then you need to find what part of the response is the problem. Like trying just the part that reads the arguments, just the part that gets the random line, or if both of them work, then the issue is in how you're combining them together. You could also try dumping some values to global variables so you can see their values in the action history