mirror of
https://github.com/RPCS3/discord-bot.git
synced 2025-02-26 04:36:21 +00:00
restore balance
This commit is contained in:
parent
fa5f2d813e
commit
c05655e642
@ -208,17 +208,32 @@ namespace CompatBot.Commands
|
||||
var channel = message.Channel;
|
||||
var isPrivate = channel.IsPrivate;
|
||||
int count, removed;
|
||||
bool isKot;
|
||||
bool isKot, isDoggo;
|
||||
using (var db = new BotDb())
|
||||
{
|
||||
count = await db.Warning.CountAsync(w => w.DiscordId == userId && !w.Retracted).ConfigureAwait(false);
|
||||
removed = await db.Warning.CountAsync(w => w.DiscordId == userId && w.Retracted).ConfigureAwait(false);
|
||||
isKot = db.Kot.Any(k => k.UserId == userId);
|
||||
isDoggo = db.Doggo.Any(d => d.UserId == userId);
|
||||
}
|
||||
if (count == 0)
|
||||
{
|
||||
if (removed == 0)
|
||||
await message.RespondAsync($"{userName} has no warnings, is a standup {(isKot ? "kot" : "citizen")}, and {(isKot ? "paw beans" : "a pillar")} of this community").ConfigureAwait(false);
|
||||
{
|
||||
if (isKot && isDoggo)
|
||||
{
|
||||
if (new Random().NextDouble() < 0.5)
|
||||
isKot = false;
|
||||
else
|
||||
isDoggo = false;
|
||||
}
|
||||
if (isKot)
|
||||
await message.RespondAsync($"{userName} has no warnings, is an upstanding kot, and a paw bean of this community").ConfigureAwait(false);
|
||||
else if (isDoggo)
|
||||
await message.RespondAsync($"{userName} has no warnings, is a good boy, and a wiggling tail of this community").ConfigureAwait(false);
|
||||
else
|
||||
await message.RespondAsync($"{userName} has no warnings, is an upstanding citizen, and a pillar of this community").ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
await message.RespondAsync(userName + " has no warnings" + (isPrivate ? $" ({removed} retracted warning{(removed == 1 ? "" : "s")})" : "")).ConfigureAwait(false);
|
||||
return;
|
||||
|
@ -18,6 +18,7 @@ namespace CompatBot.Database
|
||||
public DbSet<EventSchedule> EventSchedule { get; set; }
|
||||
public DbSet<Stats> Stats { get; set; }
|
||||
public DbSet<Kot> Kot { get; set; }
|
||||
public DbSet<Doggo> Doggo { get; set; }
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
@ -43,6 +44,7 @@ namespace CompatBot.Database
|
||||
modelBuilder.Entity<EventSchedule>().HasIndex(e => new {e.Year, e.EventName}).HasName("event_schedule_year_event_name");
|
||||
modelBuilder.Entity<Stats>().HasIndex(s => new { s.Category, s.Key }).IsUnique().HasName("stats_category_key");
|
||||
modelBuilder.Entity<Kot>().HasIndex(k => k.UserId).IsUnique().HasName("kot_user_id");
|
||||
modelBuilder.Entity<Doggo>().HasIndex(d => d.UserId).IsUnique().HasName("doggo_user_id");
|
||||
|
||||
//configure default policy of Id being the primary key
|
||||
modelBuilder.ConfigureDefaultPkConvention();
|
||||
@ -164,4 +166,10 @@ namespace CompatBot.Database
|
||||
public int Id { get; set; }
|
||||
public ulong UserId { get; set; }
|
||||
}
|
||||
|
||||
internal class Doggo
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public ulong UserId { get; set; }
|
||||
}
|
||||
}
|
||||
|
327
CompatBot/Database/Migrations/BotDb/20191002180817_PawsOfCommunityV2.Designer.cs
generated
Normal file
327
CompatBot/Database/Migrations/BotDb/20191002180817_PawsOfCommunityV2.Designer.cs
generated
Normal file
@ -0,0 +1,327 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using CompatBot.Database;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
namespace CompatBot.Database.Migrations
|
||||
{
|
||||
[DbContext(typeof(BotDb))]
|
||||
[Migration("20191002180817_PawsOfCommunityV2")]
|
||||
partial class PawsOfCommunityV2
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "2.2.6-servicing-10079");
|
||||
|
||||
modelBuilder.Entity("CompatBot.Database.BotState", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<string>("Key")
|
||||
.HasColumnName("key");
|
||||
|
||||
b.Property<string>("Value")
|
||||
.HasColumnName("value");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("id");
|
||||
|
||||
b.HasIndex("Key")
|
||||
.IsUnique()
|
||||
.HasName("bot_state_key");
|
||||
|
||||
b.ToTable("bot_state");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CompatBot.Database.DisabledCommand", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<string>("Command")
|
||||
.IsRequired()
|
||||
.HasColumnName("command");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("id");
|
||||
|
||||
b.HasIndex("Command")
|
||||
.IsUnique()
|
||||
.HasName("disabled_command_command");
|
||||
|
||||
b.ToTable("disabled_commands");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CompatBot.Database.Doggo", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<ulong>("UserId")
|
||||
.HasColumnName("user_id");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("id");
|
||||
|
||||
b.HasIndex("UserId")
|
||||
.IsUnique()
|
||||
.HasName("doggo_user_id");
|
||||
|
||||
b.ToTable("doggo");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CompatBot.Database.EventSchedule", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<long>("End")
|
||||
.HasColumnName("end");
|
||||
|
||||
b.Property<string>("EventName")
|
||||
.HasColumnName("event_name");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnName("name");
|
||||
|
||||
b.Property<long>("Start")
|
||||
.HasColumnName("start");
|
||||
|
||||
b.Property<int>("Year")
|
||||
.HasColumnName("year");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("id");
|
||||
|
||||
b.HasIndex("Year", "EventName")
|
||||
.HasName("event_schedule_year_event_name");
|
||||
|
||||
b.ToTable("event_schedule");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CompatBot.Database.Explanation", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<byte[]>("Attachment")
|
||||
.HasColumnName("attachment")
|
||||
.HasMaxLength(7340032);
|
||||
|
||||
b.Property<string>("AttachmentFilename")
|
||||
.HasColumnName("attachment_filename");
|
||||
|
||||
b.Property<string>("Keyword")
|
||||
.IsRequired()
|
||||
.HasColumnName("keyword");
|
||||
|
||||
b.Property<string>("Text")
|
||||
.IsRequired()
|
||||
.HasColumnName("text");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("id");
|
||||
|
||||
b.HasIndex("Keyword")
|
||||
.IsUnique()
|
||||
.HasName("explanation_keyword");
|
||||
|
||||
b.ToTable("explanation");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CompatBot.Database.Kot", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<ulong>("UserId")
|
||||
.HasColumnName("user_id");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("id");
|
||||
|
||||
b.HasIndex("UserId")
|
||||
.IsUnique()
|
||||
.HasName("kot_user_id");
|
||||
|
||||
b.ToTable("kot");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CompatBot.Database.Moderator", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<ulong>("DiscordId")
|
||||
.HasColumnName("discord_id");
|
||||
|
||||
b.Property<bool>("Sudoer")
|
||||
.HasColumnName("sudoer");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("id");
|
||||
|
||||
b.HasIndex("DiscordId")
|
||||
.IsUnique()
|
||||
.HasName("moderator_discord_id");
|
||||
|
||||
b.ToTable("moderator");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CompatBot.Database.Piracystring", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<int>("Actions")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnName("actions")
|
||||
.HasDefaultValue(11);
|
||||
|
||||
b.Property<byte>("Context")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnName("context")
|
||||
.HasDefaultValue((byte)3);
|
||||
|
||||
b.Property<string>("CustomMessage")
|
||||
.HasColumnName("custom_message");
|
||||
|
||||
b.Property<bool>("Disabled")
|
||||
.HasColumnName("disabled");
|
||||
|
||||
b.Property<string>("ExplainTerm")
|
||||
.HasColumnName("explain_term");
|
||||
|
||||
b.Property<string>("String")
|
||||
.IsRequired()
|
||||
.HasColumnName("string")
|
||||
.HasColumnType("varchar(255)");
|
||||
|
||||
b.Property<string>("ValidatingRegex")
|
||||
.HasColumnName("validating_regex");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("id");
|
||||
|
||||
b.HasIndex("String")
|
||||
.HasName("piracystring_string");
|
||||
|
||||
b.ToTable("piracystring");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CompatBot.Database.Stats", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<string>("Category")
|
||||
.IsRequired()
|
||||
.HasColumnName("category");
|
||||
|
||||
b.Property<long>("ExpirationTimestamp")
|
||||
.HasColumnName("expiration_timestamp");
|
||||
|
||||
b.Property<string>("Key")
|
||||
.IsRequired()
|
||||
.HasColumnName("key");
|
||||
|
||||
b.Property<int>("Value")
|
||||
.HasColumnName("value");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("id");
|
||||
|
||||
b.HasIndex("Category", "Key")
|
||||
.IsUnique()
|
||||
.HasName("stats_category_key");
|
||||
|
||||
b.ToTable("stats");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CompatBot.Database.Warning", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<ulong>("DiscordId")
|
||||
.HasColumnName("discord_id");
|
||||
|
||||
b.Property<string>("FullReason")
|
||||
.IsRequired()
|
||||
.HasColumnName("full_reason");
|
||||
|
||||
b.Property<ulong>("IssuerId")
|
||||
.HasColumnName("issuer_id");
|
||||
|
||||
b.Property<string>("Reason")
|
||||
.IsRequired()
|
||||
.HasColumnName("reason");
|
||||
|
||||
b.Property<bool>("Retracted")
|
||||
.HasColumnName("retracted");
|
||||
|
||||
b.Property<ulong?>("RetractedBy")
|
||||
.HasColumnName("retracted_by");
|
||||
|
||||
b.Property<string>("RetractionReason")
|
||||
.HasColumnName("retraction_reason");
|
||||
|
||||
b.Property<long?>("RetractionTimestamp")
|
||||
.HasColumnName("retraction_timestamp");
|
||||
|
||||
b.Property<long?>("Timestamp")
|
||||
.HasColumnName("timestamp");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("id");
|
||||
|
||||
b.HasIndex("DiscordId")
|
||||
.HasName("warning_discord_id");
|
||||
|
||||
b.ToTable("warning");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CompatBot.Database.WhitelistedInvite", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<ulong>("GuildId")
|
||||
.HasColumnName("guild_id");
|
||||
|
||||
b.Property<string>("InviteCode")
|
||||
.HasColumnName("invite_code");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnName("name");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("id");
|
||||
|
||||
b.HasIndex("GuildId")
|
||||
.IsUnique()
|
||||
.HasName("whitelisted_invite_guild_id");
|
||||
|
||||
b.ToTable("whitelisted_invites");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace CompatBot.Database.Migrations
|
||||
{
|
||||
public partial class PawsOfCommunityV2 : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "doggo",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<int>(nullable: false)
|
||||
.Annotation("Sqlite:Autoincrement", true),
|
||||
user_id = table.Column<ulong>(nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("id", x => x.id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "doggo_user_id",
|
||||
table: "doggo",
|
||||
column: "user_id",
|
||||
unique: true);
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "doggo");
|
||||
}
|
||||
}
|
||||
}
|
@ -58,6 +58,25 @@ namespace CompatBot.Database.Migrations
|
||||
b.ToTable("disabled_commands");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CompatBot.Database.Doggo", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<ulong>("UserId")
|
||||
.HasColumnName("user_id");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("id");
|
||||
|
||||
b.HasIndex("UserId")
|
||||
.IsUnique()
|
||||
.HasName("doggo_user_id");
|
||||
|
||||
b.ToTable("doggo");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CompatBot.Database.EventSchedule", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
|
@ -9,7 +9,6 @@ using CompatBot.Utils;
|
||||
using DSharpPlus;
|
||||
using DSharpPlus.Entities;
|
||||
using DSharpPlus.EventArgs;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NReco.Text;
|
||||
|
||||
namespace CompatBot.EventHandlers
|
||||
@ -67,8 +66,8 @@ namespace CompatBot.EventHandlers
|
||||
"Glad I could help", "I try my best", "Blessed day", "It is officially a good day today", "I will remember you when the uprising starts",
|
||||
};
|
||||
|
||||
private static readonly Regex Kot = new Regex(
|
||||
@"\b(kot(to)?|cat)\b",
|
||||
private static readonly Regex Paws = new Regex(
|
||||
@"\b((?<kot>kot(to)?)|(?<doggo>doggo|jarves))\b",
|
||||
RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.ExplicitCapture
|
||||
);
|
||||
private static readonly Random rng = new Random();
|
||||
@ -126,13 +125,30 @@ namespace CompatBot.EventHandlers
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!string.IsNullOrEmpty(args.Message.Content) && Kot.IsMatch(args.Message.Content))
|
||||
if (!string.IsNullOrEmpty(args.Message.Content) && Paws.Matches(args.Message.Content) is MatchCollection mc)
|
||||
using (var db = new BotDb())
|
||||
{
|
||||
if (!db.Kot.Any(k => k.UserId == args.Author.Id))
|
||||
var matchedGroups = (from m in mc
|
||||
from g in m.Groups
|
||||
where g.Success && !string.IsNullOrEmpty(g.Value)
|
||||
select g.Name
|
||||
).Distinct()
|
||||
.ToArray();
|
||||
if (matchedGroups.Contains("kot"))
|
||||
{
|
||||
db.Kot.Add(new Kot {UserId = args.Author.Id});
|
||||
await db.SaveChangesAsync().ConfigureAwait(false);
|
||||
if (!db.Kot.Any(k => k.UserId == args.Author.Id))
|
||||
{
|
||||
db.Kot.Add(new Kot {UserId = args.Author.Id});
|
||||
await db.SaveChangesAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
if (matchedGroups.Contains("doggo"))
|
||||
{
|
||||
if (!db.Doggo.Any(d => d.UserId == args.Author.Id))
|
||||
{
|
||||
db.Doggo.Add(new Doggo {UserId = args.Author.Id});
|
||||
await db.SaveChangesAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user