我想在文件“B”中使用文件“a”中的一个变量。我在网上搜索了一下,但还是不行。
所以我得到了文件“bot.cs”和文件“profanityfilter.cs”。
在ProfanityFilter.cs中,我想使用bot.cs中的“IncommingMessage”。
bot.cs:
class Bot
{
public static void Client_OnMessageReceived(object sender, OnMessageReceivedArgs e)
{
var incommingMessage = e.ChatMessage.Message;
//Profanity filter testing received message (need to get incomming message over to
profanityFilter.cs)
profanityFilter.Filter();
Console.WriteLine($"[{TwitchInformation.BotName}]: [{e.ChatMessage.DisplayName}]:
{e.ChatMessage.Message}");
}
}
ProfanityFilter.cs:
class profanityFilter
{
public static async void Filter()
{
var client = new HttpClient();
Bot message = new Bot();
var incommingMessagesFromUser = message.Client_OnMessageReceived.IncommingMessages;
var request = new HttpRequestMessage
{
Method = HttpMethod.Post,
RequestUri = new Uri("https://neutrinoapi-bad-word-filter.p.rapidapi.com/bad-word-filter"),
Headers =
{
{ "x-rapidapi-key", "xxx" },
{ "x-rapidapi-host", "neutrinoapi-bad-word-filter.p.rapidapi.com" },
},
Content = new FormUrlEncodedContent(new Dictionary<string, string>
{[enter image description here][1]
{ "censor-character", "*" },
{ "content", incommingMessagesFromUser },
}),
};
using (var response = await client.SendAsync(request))
{
response.EnsureSuccessStatusCode();
var body = await response.Content.ReadAsStringAsync();
Console.WriteLine(body);
}
}
}
但这给了我如下图所示的错误:
我认为您应该考虑创建一个Events和EventHandlers,它可以让类注册到事件,然后消费/处理这些事件。实际上,您的bot
类将引发一个事件,您的ProfanityFilter
可能会注册并使用该事件。
虽然我不确定我是否同意使用亵渎过滤器来监听事件,但这是一个架构选择。我可能会有一个编排类,它注册到bots事件,使用它,调用亵渎过滤器,然后继续执行此后所需的任何逻辑。
在C#中,类名通常也是Pascal大小写的