'cleverbot should be available on the public bot now
This commit is contained in:
parent
7d6a7f159b
commit
2e8e4daa25
4 changed files with 48 additions and 31 deletions
|
@ -182,16 +182,6 @@ public static class GuildConfigExtensions
|
||||||
.SelectMany(gc => gc.FollowedStreams)
|
.SelectMany(gc => gc.FollowedStreams)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
public static void SetCleverbotEnabled(this DbSet<GuildConfig> configs, ulong id, bool cleverbotEnabled)
|
|
||||||
{
|
|
||||||
var conf = configs.FirstOrDefault(gc => gc.GuildId == id);
|
|
||||||
|
|
||||||
if (conf is null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
conf.CleverbotEnabled = cleverbotEnabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static XpSettings XpSettingsFor(this DbContext ctx, ulong guildId)
|
public static XpSettings XpSettingsFor(this DbContext ctx, ulong guildId)
|
||||||
{
|
{
|
||||||
var gc = ctx.GuildConfigsForId(guildId,
|
var gc = ctx.GuildConfigsForId(guildId,
|
||||||
|
|
|
@ -18,31 +18,18 @@ public partial class Games
|
||||||
[Cmd]
|
[Cmd]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[UserPerm(GuildPerm.ManageMessages)]
|
[UserPerm(GuildPerm.ManageMessages)]
|
||||||
[NoPublicBot]
|
|
||||||
public async Task CleverBot()
|
public async Task CleverBot()
|
||||||
{
|
{
|
||||||
var channel = (ITextChannel)ctx.Channel;
|
var channel = (ITextChannel)ctx.Channel;
|
||||||
|
|
||||||
if (_service.ChatterBotGuilds.TryRemove(channel.Guild.Id, out _))
|
var newState = await _service.ToggleChatterBotAsync(ctx.Guild.Id);
|
||||||
{
|
|
||||||
await using (var uow = _db.GetDbContext())
|
|
||||||
{
|
|
||||||
uow.Set<GuildConfig>().SetCleverbotEnabled(ctx.Guild.Id, false);
|
|
||||||
await uow.SaveChangesAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (!newState)
|
||||||
|
{
|
||||||
await Response().Confirm(strs.chatbot_disabled).SendAsync();
|
await Response().Confirm(strs.chatbot_disabled).SendAsync();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_service.ChatterBotGuilds.TryAdd(channel.Guild.Id, new(() => _service.CreateSession(), true));
|
|
||||||
|
|
||||||
await using (var uow = _db.GetDbContext())
|
|
||||||
{
|
|
||||||
uow.Set<GuildConfig>().SetCleverbotEnabled(ctx.Guild.Id, true);
|
|
||||||
await uow.SaveChangesAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
await Response().Confirm(strs.chatbot_enabled).SendAsync();
|
await Response().Confirm(strs.chatbot_enabled).SendAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
using LinqToDB;
|
||||||
|
using LinqToDB.EntityFrameworkCore;
|
||||||
using EllieBot.Common.ModuleBehaviors;
|
using EllieBot.Common.ModuleBehaviors;
|
||||||
|
using EllieBot.Db.Models;
|
||||||
using EllieBot.Modules.Games.Common;
|
using EllieBot.Modules.Games.Common;
|
||||||
using EllieBot.Modules.Games.Common.ChatterBot;
|
using EllieBot.Modules.Games.Common.ChatterBot;
|
||||||
using EllieBot.Modules.Patronage;
|
using EllieBot.Modules.Patronage;
|
||||||
|
@ -9,7 +12,7 @@ namespace EllieBot.Modules.Games.Services;
|
||||||
|
|
||||||
public class ChatterBotService : IExecOnMessage
|
public class ChatterBotService : IExecOnMessage
|
||||||
{
|
{
|
||||||
public ConcurrentDictionary<ulong, Lazy<IChatterBotSession>> ChatterBotGuilds { get; }
|
private ConcurrentDictionary<ulong, Lazy<IChatterBotSession>> ChatterBotGuilds { get; }
|
||||||
|
|
||||||
public int Priority
|
public int Priority
|
||||||
=> 1;
|
=> 1;
|
||||||
|
@ -20,6 +23,7 @@ public class ChatterBotService : IExecOnMessage
|
||||||
private readonly IHttpClientFactory _httpFactory;
|
private readonly IHttpClientFactory _httpFactory;
|
||||||
private readonly GamesConfigService _gcs;
|
private readonly GamesConfigService _gcs;
|
||||||
private readonly IMessageSenderService _sender;
|
private readonly IMessageSenderService _sender;
|
||||||
|
private readonly DbService _db;
|
||||||
public readonly IPatronageService _ps;
|
public readonly IPatronageService _ps;
|
||||||
|
|
||||||
public ChatterBotService(
|
public ChatterBotService(
|
||||||
|
@ -30,12 +34,14 @@ public class ChatterBotService : IExecOnMessage
|
||||||
IHttpClientFactory factory,
|
IHttpClientFactory factory,
|
||||||
IBotCredentials creds,
|
IBotCredentials creds,
|
||||||
GamesConfigService gcs,
|
GamesConfigService gcs,
|
||||||
IMessageSenderService sender)
|
IMessageSenderService sender,
|
||||||
|
DbService db)
|
||||||
{
|
{
|
||||||
_client = client;
|
_client = client;
|
||||||
_perms = perms;
|
_perms = perms;
|
||||||
_creds = creds;
|
_creds = creds;
|
||||||
_sender = sender;
|
_sender = sender;
|
||||||
|
_db = db;
|
||||||
_httpFactory = factory;
|
_httpFactory = factory;
|
||||||
_perms = perms;
|
_perms = perms;
|
||||||
_gcs = gcs;
|
_gcs = gcs;
|
||||||
|
@ -196,4 +202,38 @@ public class ChatterBotService : IExecOnMessage
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<bool> ToggleChatterBotAsync(ulong guildId)
|
||||||
|
{
|
||||||
|
if (ChatterBotGuilds.TryRemove(guildId, out _))
|
||||||
|
{
|
||||||
|
await using var uow = _db.GetDbContext();
|
||||||
|
await uow.Set<GuildConfig>()
|
||||||
|
.ToLinqToDBTable()
|
||||||
|
.Where(x => x.GuildId == guildId)
|
||||||
|
.UpdateAsync((gc) => new GuildConfig()
|
||||||
|
{
|
||||||
|
CleverbotEnabled = false
|
||||||
|
});
|
||||||
|
await uow.SaveChangesAsync();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ChatterBotGuilds.TryAdd(guildId, new(() => CreateSession(), true));
|
||||||
|
|
||||||
|
await using (var uow = _db.GetDbContext())
|
||||||
|
{
|
||||||
|
await uow.Set<GuildConfig>()
|
||||||
|
.ToLinqToDBTable()
|
||||||
|
.Where(x => x.GuildId == guildId)
|
||||||
|
.UpdateAsync((gc) => new GuildConfig()
|
||||||
|
{
|
||||||
|
CleverbotEnabled = true
|
||||||
|
});
|
||||||
|
|
||||||
|
await uow.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1361,10 +1361,10 @@ flip:
|
||||||
desc: "The number of times the coin is flipped."
|
desc: "The number of times the coin is flipped."
|
||||||
betflip:
|
betflip:
|
||||||
desc: |-
|
desc: |-
|
||||||
Bet to guess will the result be heads or tails.
|
Bet on the coin flip.
|
||||||
Guessing awards you 1.95x the currency you've bet (rounded up).
|
The result can be heads or tails.
|
||||||
|
Guessing correctly rewards you with 1.95x of the currency you've bet (rounded up).
|
||||||
Multiplier can be changed by the bot owner.
|
Multiplier can be changed by the bot owner.
|
||||||
|
|
||||||
ex:
|
ex:
|
||||||
- 5 heads
|
- 5 heads
|
||||||
- 3 t
|
- 3 t
|
||||||
|
|
Loading…
Reference in a new issue