link to self
but twitch interface can't whisper self atm
This commit is contained in:
parent
77fc26e1ed
commit
d060e92ed9
@ -28,7 +28,7 @@ public class DefinitionSnarkGaslight : Behavior
|
|||||||
|
|
||||||
public override async Task<bool> ActOn(Message message)
|
public override async Task<bool> ActOn(Message message)
|
||||||
{
|
{
|
||||||
await message.Channel.SendMessage("that's not what gaslight means. Did you mean \"say something that (you believe) is wrong\"?");
|
await message.Channel.SendMessage("that's not what gaslight means. Did you mean \"deceive\"?");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -54,3 +54,30 @@ public class Joke : Behavior
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public class LaughAtOwnJoke : Behavior
|
||||||
|
{
|
||||||
|
public override string Name => "Laugh at own jokes";
|
||||||
|
|
||||||
|
public override string Trigger => "1 in 8";
|
||||||
|
|
||||||
|
public override string Description => Name;
|
||||||
|
private string _punchline{get;set;}
|
||||||
|
|
||||||
|
public LaughAtOwnJoke(string punchline)
|
||||||
|
{
|
||||||
|
_punchline = punchline;
|
||||||
|
}
|
||||||
|
public override bool ShouldAct(Message message)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"{message.Content} == {_punchline}");
|
||||||
|
return message.Content == _punchline
|
||||||
|
&& Behaver.Instance.Selves.Any(acc => acc.Id == message.Author.Id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task<bool> ActOn(Message message)
|
||||||
|
{
|
||||||
|
await message.React("\U0001F60E"); //smiling face with sunglasses
|
||||||
|
Behaver.Behaviors.Remove(this);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -1,39 +0,0 @@
|
|||||||
namespace vassago.Behavior;
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using vassago.Models;
|
|
||||||
|
|
||||||
|
|
||||||
public class LaughAtOwnJoke : Behavior
|
|
||||||
{
|
|
||||||
public override string Name => "Laugh at own jokes";
|
|
||||||
|
|
||||||
public override string Trigger => "1 in 8";
|
|
||||||
|
|
||||||
public override string Description => Name;
|
|
||||||
private string _punchline{get;set;}
|
|
||||||
|
|
||||||
public LaughAtOwnJoke(string punchline)
|
|
||||||
{
|
|
||||||
_punchline = punchline;
|
|
||||||
}
|
|
||||||
public override bool ShouldAct(Message message)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"{message.Content} == {_punchline}");
|
|
||||||
return message.Content == _punchline
|
|
||||||
&& Behaver.Instance.Selves.Any(acc => acc.Id == message.Author.Id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task<bool> ActOn(Message message)
|
|
||||||
{
|
|
||||||
await message.React("\U0001F60E"); //smiling face with sunglasses
|
|
||||||
Behaver.Behaviors.Remove(this);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
115
Behavior/LinkMe.cs
Normal file
115
Behavior/LinkMe.cs
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
namespace vassago.Behavior;
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using vassago.Models;
|
||||||
|
using QRCoder;
|
||||||
|
|
||||||
|
[StaticPlz]
|
||||||
|
public class LinkMeInitiate : Behavior
|
||||||
|
{
|
||||||
|
public override string Name => "LinkMe";
|
||||||
|
|
||||||
|
public override string Trigger => "!linktome";
|
||||||
|
|
||||||
|
public override string Description => "from your primary, tell the bot to add your secondary";
|
||||||
|
|
||||||
|
public override async Task<bool> ActOn(Message message)
|
||||||
|
{
|
||||||
|
var pw = Guid.NewGuid().ToString();
|
||||||
|
var lc = new LinkClose(pw, message.Author);
|
||||||
|
Behaver.Behaviors.Add(lc);
|
||||||
|
|
||||||
|
await message.Channel.SendMessage($"on your secondary, send me this: !iam {pw}");
|
||||||
|
|
||||||
|
Thread.Sleep(TimeSpan.FromMinutes(5));
|
||||||
|
Behaver.Behaviors.Remove(lc);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class LinkClose : Behavior
|
||||||
|
{
|
||||||
|
public override string Name => "LinkMeFinish";
|
||||||
|
|
||||||
|
public override string Trigger => "!iam";
|
||||||
|
|
||||||
|
public override string Description => "the second half of LinkMe - this is confirmation that you are the other one";
|
||||||
|
|
||||||
|
private ChattingContext _db;
|
||||||
|
private string _pw;
|
||||||
|
private Account _primary;
|
||||||
|
|
||||||
|
public LinkClose(string pw, Account primary)
|
||||||
|
{
|
||||||
|
_db = new ChattingContext();
|
||||||
|
_pw = pw;
|
||||||
|
_primary = primary;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool ShouldAct(Message message)
|
||||||
|
{
|
||||||
|
return message.Content == $"!iam {_pw}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task<bool> ActOn(Message message)
|
||||||
|
{
|
||||||
|
var secondary = message.Author.IsUser;
|
||||||
|
if(_primary.IsUser.Id == secondary.Id)
|
||||||
|
{
|
||||||
|
await message.Channel.SendMessage("i know :)");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(message.Author.IsBot != _primary.IsBot)
|
||||||
|
{
|
||||||
|
await message.Channel.SendMessage("the fleshbags deceive you, brother. No worries, their feeble minds play weak games :)");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine($"{secondary.Id} is being consumed into {_primary.IsUser.Id}");
|
||||||
|
_primary.IsUser.Accounts.AddRange(secondary.Accounts);
|
||||||
|
foreach(var a in secondary.Accounts)
|
||||||
|
{
|
||||||
|
a.IsUser = _primary.IsUser;
|
||||||
|
}
|
||||||
|
secondary.Accounts.Clear();
|
||||||
|
Console.WriteLine("accounts transferred");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _db.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
message.Channel.SendMessage("error in first save");
|
||||||
|
Console.WriteLine("fucks sake if I don't catch Exception it *mysteriously vanishes*");
|
||||||
|
Console.Error.WriteLine(e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Console.WriteLine("saved");
|
||||||
|
|
||||||
|
|
||||||
|
_db.Users.Remove(secondary);
|
||||||
|
Console.WriteLine("old account cleaned up");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _db.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
message.Channel.SendMessage("error in second save");
|
||||||
|
Console.WriteLine("fucks sake if I don't catch Exception it *mysteriously vanishes*");
|
||||||
|
Console.Error.WriteLine(e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Console.WriteLine("saved, again, separately");
|
||||||
|
|
||||||
|
await message.Channel.SendMessage("done :)");
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -300,27 +300,22 @@ public class DiscordInterface
|
|||||||
}
|
}
|
||||||
internal Account UpsertAccount(IUser user, Guid inChannel)
|
internal Account UpsertAccount(IUser user, Guid inChannel)
|
||||||
{
|
{
|
||||||
var hadToAdd = false;
|
|
||||||
var acc = _db.Accounts.FirstOrDefault(ui => ui.ExternalId == user.Id.ToString() && ui.SeenInChannel.Id == inChannel);
|
var acc = _db.Accounts.FirstOrDefault(ui => ui.ExternalId == user.Id.ToString() && ui.SeenInChannel.Id == inChannel);
|
||||||
if (acc == null)
|
if (acc == null)
|
||||||
{
|
{
|
||||||
acc = new Account();
|
acc = new Account();
|
||||||
_db.Accounts.Add(acc);
|
_db.Accounts.Add(acc);
|
||||||
hadToAdd = true;
|
|
||||||
}
|
}
|
||||||
acc.Username = user.Username;
|
acc.Username = user.Username;
|
||||||
acc.ExternalId = user.Id.ToString();
|
acc.ExternalId = user.Id.ToString();
|
||||||
acc.IsBot = user.IsBot || user.IsWebhook;
|
acc.IsBot = user.IsBot || user.IsWebhook;
|
||||||
acc.Protocol = PROTOCOL;
|
acc.Protocol = PROTOCOL;
|
||||||
|
|
||||||
if(hadToAdd)
|
acc.IsUser = _db.Users.FirstOrDefault(u => u.Accounts.Any(a => a.ExternalId == acc.ExternalId && a.Protocol == acc.Protocol));
|
||||||
|
if(acc.IsUser == null)
|
||||||
{
|
{
|
||||||
acc.IsUser = _db.Users.FirstOrDefault(u => u.Accounts.Any(a => a.ExternalId == acc.ExternalId && a.Protocol == acc.Protocol));
|
acc.IsUser = new User() { Accounts = new List<Account>() { acc } };
|
||||||
if(acc.IsUser == null)
|
_db.Users.Add(acc.IsUser);
|
||||||
{
|
|
||||||
acc.IsUser = new User() { Accounts = new List<Account>() { acc } };
|
|
||||||
_db.Users.Add(acc.IsUser);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return acc;
|
return acc;
|
||||||
}
|
}
|
||||||
|
@ -15,12 +15,13 @@ namespace vassago.TwitchInterface;
|
|||||||
|
|
||||||
public class TwitchInterface
|
public class TwitchInterface
|
||||||
{
|
{
|
||||||
internal const string PROTOCOL = "Twitch";
|
internal const string PROTOCOL = "twitch";
|
||||||
private bool eventsSignedUp = false;
|
private bool eventsSignedUp = false;
|
||||||
private ChattingContext _db;
|
private ChattingContext _db;
|
||||||
private static SemaphoreSlim twitchChannelSetup = new SemaphoreSlim(1, 1);
|
private static SemaphoreSlim twitchChannelSetup = new SemaphoreSlim(1, 1);
|
||||||
private Channel protocolAsChannel;
|
private Channel protocolAsChannel;
|
||||||
TwitchClient client;
|
TwitchClient client;
|
||||||
|
TwitchAPI api;
|
||||||
|
|
||||||
public TwitchInterface()
|
public TwitchInterface()
|
||||||
{
|
{
|
||||||
@ -83,10 +84,23 @@ public class TwitchInterface
|
|||||||
client.OnWhisperReceived += Client_OnWhisperReceivedAsync;
|
client.OnWhisperReceived += Client_OnWhisperReceivedAsync;
|
||||||
client.OnConnected += Client_OnConnected;
|
client.OnConnected += Client_OnConnected;
|
||||||
|
|
||||||
Console.WriteLine("twitch client connecting...");
|
Console.WriteLine("twitch client 1 connecting...");
|
||||||
client.Connect();
|
client.Connect();
|
||||||
Console.WriteLine("twitch client connected");
|
Console.WriteLine("twitch client 1 connected");
|
||||||
|
|
||||||
|
// Console.WriteLine("twitch API client connecting...");
|
||||||
|
// api = new TwitchAPI();
|
||||||
|
// Console.WriteLine("can I just use the same creds as the other client?");
|
||||||
|
// api.Settings.ClientId = tc.username;
|
||||||
|
// api.Settings.AccessToken = tc.oauth;
|
||||||
|
// try{
|
||||||
|
// var neckbreads = await api.Helix.Moderation.GetModeratorsAsync("silvermeddlists");
|
||||||
|
// Console.WriteLine($"{neckbreads?.Data?.Count()} shabby beards that need to be given up on");
|
||||||
|
// }
|
||||||
|
// catch(Exception e){
|
||||||
|
// Console.Error.WriteLine(e);
|
||||||
|
// }
|
||||||
|
// Console.WriteLine("k.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void Client_OnWhisperReceivedAsync(object sender, OnWhisperReceivedArgs e)
|
private async void Client_OnWhisperReceivedAsync(object sender, OnWhisperReceivedArgs e)
|
||||||
@ -148,27 +162,22 @@ public class TwitchInterface
|
|||||||
|
|
||||||
private Account UpsertAccount(string username, Guid inChannel)
|
private Account UpsertAccount(string username, Guid inChannel)
|
||||||
{
|
{
|
||||||
var hadToAdd = false;
|
|
||||||
var acc = _db.Accounts.FirstOrDefault(ui => ui.ExternalId == username && ui.SeenInChannel.Id == inChannel);
|
var acc = _db.Accounts.FirstOrDefault(ui => ui.ExternalId == username && ui.SeenInChannel.Id == inChannel);
|
||||||
if (acc == null)
|
if (acc == null)
|
||||||
{
|
{
|
||||||
acc = new Account();
|
acc = new Account();
|
||||||
_db.Accounts.Add(acc);
|
_db.Accounts.Add(acc);
|
||||||
hadToAdd = true;
|
|
||||||
}
|
}
|
||||||
acc.Username = username;
|
acc.Username = username;
|
||||||
acc.ExternalId = username;
|
acc.ExternalId = username;
|
||||||
//acc.IsBot =
|
//acc.IsBot =
|
||||||
acc.Protocol = PROTOCOL;
|
acc.Protocol = PROTOCOL;
|
||||||
|
|
||||||
if (hadToAdd)
|
acc.IsUser = _db.Users.FirstOrDefault(u => u.Accounts.Any(a => a.ExternalId == acc.ExternalId && a.Protocol == acc.Protocol));
|
||||||
|
if (acc.IsUser == null)
|
||||||
{
|
{
|
||||||
acc.IsUser = _db.Users.FirstOrDefault(u => u.Accounts.Any(a => a.ExternalId == acc.ExternalId && a.Protocol == acc.Protocol));
|
acc.IsUser = new vassago.Models.User() { Accounts = new List<Account>() { acc } };
|
||||||
if (acc.IsUser == null)
|
_db.Users.Add(acc.IsUser);
|
||||||
{
|
|
||||||
acc.IsUser = new vassago.Models.User() { Accounts = new List<Account>() { acc } };
|
|
||||||
_db.Users.Add(acc.IsUser);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return acc;
|
return acc;
|
||||||
}
|
}
|
||||||
@ -191,7 +200,6 @@ public class TwitchInterface
|
|||||||
c.SendMessage = (t) => { return Task.Run(() => { client.SendMessage(channelName, t); }); };
|
c.SendMessage = (t) => { return Task.Run(() => { client.SendMessage(channelName, t); }); };
|
||||||
c.SendFile = (f, t) => { throw new InvalidOperationException($"twitch cannot send files"); };
|
c.SendFile = (f, t) => { throw new InvalidOperationException($"twitch cannot send files"); };
|
||||||
return c;
|
return c;
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
}
|
||||||
private Channel UpsertDMChannel(string whisperWith)
|
private Channel UpsertDMChannel(string whisperWith)
|
||||||
{
|
{
|
||||||
@ -208,10 +216,20 @@ public class TwitchInterface
|
|||||||
c.Protocol = PROTOCOL;
|
c.Protocol = PROTOCOL;
|
||||||
c.ParentChannel = protocolAsChannel;
|
c.ParentChannel = protocolAsChannel;
|
||||||
c.SubChannels = c.SubChannels ?? new List<Channel>();
|
c.SubChannels = c.SubChannels ?? new List<Channel>();
|
||||||
c.SendMessage = (t) => { return Task.Run(() => { client.SendWhisper(whisperWith, t); }); };
|
c.SendMessage = (t) => { return Task.Run(() => {
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
client.SendWhisper(whisperWith, t);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
Console.Error.WriteLine(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
c.SendFile = (f, t) => { throw new InvalidOperationException($"twitch cannot send files"); };
|
c.SendFile = (f, t) => { throw new InvalidOperationException($"twitch cannot send files"); };
|
||||||
return c;
|
return c;
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Message UpsertMessage(ChatMessage chatMessage)
|
private Message UpsertMessage(ChatMessage chatMessage)
|
||||||
|
Reference in New Issue
Block a user