commit
d3b46c53ac
@ -1 +1 @@
|
|||||||
Subproject commit e8550fa462f86e0338925547dfe99242bfc1fdcc
|
Subproject commit b51408def863ee5f4273478efa65eb50e4008487
|
18
src/NadekoBot/Attributes/LocalizedAlias.cs
Normal file
18
src/NadekoBot/Attributes/LocalizedAlias.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
using Discord.Commands;
|
||||||
|
using NadekoBot.Services;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NadekoBot.Attributes
|
||||||
|
{
|
||||||
|
public class LocalizedAliasAttribute : AliasAttribute
|
||||||
|
{
|
||||||
|
public LocalizedAliasAttribute([CallerMemberName] string memberName = "") : base(Localization.LoadCommandString(memberName.ToLowerInvariant() + "_text").Split(' ').Skip(1).ToArray())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,12 +1,13 @@
|
|||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using NadekoBot.Services;
|
using NadekoBot.Services;
|
||||||
|
using System.Linq;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
namespace NadekoBot.Attributes
|
namespace NadekoBot.Attributes
|
||||||
{
|
{
|
||||||
public class LocalizedCommandAttribute : CommandAttribute
|
public class LocalizedCommandAttribute : CommandAttribute
|
||||||
{
|
{
|
||||||
public LocalizedCommandAttribute([CallerMemberName] string memberName="") : base(Localization.LoadCommandString(memberName.ToLowerInvariant() + "_text"))
|
public LocalizedCommandAttribute([CallerMemberName] string memberName="") : base(Localization.LoadCommandString(memberName.ToLowerInvariant() + "_text").Split(' ')[0])
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
52
src/NadekoBot/Attributes/NadekoModule.cs
Normal file
52
src/NadekoBot/Attributes/NadekoModule.cs
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
using Discord.Commands;
|
||||||
|
using NadekoBot.Services;
|
||||||
|
using NadekoBot.Services.Database;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NadekoBot.Attributes
|
||||||
|
{
|
||||||
|
[System.AttributeUsage(AttributeTargets.Class)]
|
||||||
|
sealed class NadekoModuleAttribute : ModuleAttribute
|
||||||
|
{
|
||||||
|
//modulename / prefix
|
||||||
|
private static Dictionary<string, string> modulePrefixes = null;
|
||||||
|
public static Dictionary<string, string> ModulePrefixes {
|
||||||
|
get {
|
||||||
|
if (modulePrefixes != null)
|
||||||
|
return modulePrefixes;
|
||||||
|
|
||||||
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
|
{
|
||||||
|
return (modulePrefixes = uow.BotConfig
|
||||||
|
.GetOrCreate()
|
||||||
|
.ModulePrefixes
|
||||||
|
.ToDictionary(p => p.ModuleName, p => p.Prefix));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public NadekoModuleAttribute(string moduleName, string defaultPrefix) : base(GetModulePrefix(moduleName) ?? defaultPrefix)
|
||||||
|
{
|
||||||
|
AppendSpace = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string GetModulePrefix(string moduleName)
|
||||||
|
{
|
||||||
|
string prefix;
|
||||||
|
if (ModulePrefixes.TryGetValue(moduleName, out prefix))
|
||||||
|
{
|
||||||
|
Console.WriteLine("Cache hit");
|
||||||
|
return prefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine("Cache not hit for " + moduleName);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -8,7 +8,7 @@ using NadekoBot.Services.Database.Impl;
|
|||||||
namespace NadekoBot.Migrations
|
namespace NadekoBot.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(NadekoSqliteContext))]
|
[DbContext(typeof(NadekoSqliteContext))]
|
||||||
[Migration("20160828000228_first")]
|
[Migration("20160910180231_first")]
|
||||||
partial class first
|
partial class first
|
||||||
{
|
{
|
||||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
@ -39,6 +39,10 @@ namespace NadekoBot.Migrations
|
|||||||
|
|
||||||
b.Property<ulong>("BufferSize");
|
b.Property<ulong>("BufferSize");
|
||||||
|
|
||||||
|
b.Property<float>("CurrencyGenerationChance");
|
||||||
|
|
||||||
|
b.Property<int>("CurrencyGenerationCooldown");
|
||||||
|
|
||||||
b.Property<string>("CurrencyName");
|
b.Property<string>("CurrencyName");
|
||||||
|
|
||||||
b.Property<string>("CurrencyPluralName");
|
b.Property<string>("CurrencyPluralName");
|
||||||
@ -104,6 +108,39 @@ namespace NadekoBot.Migrations
|
|||||||
b.ToTable("ClashOfClans");
|
b.ToTable("ClashOfClans");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.ConvertUnit", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
b.Property<string>("InternalTrigger");
|
||||||
|
|
||||||
|
b.Property<decimal>("Modifier");
|
||||||
|
|
||||||
|
b.Property<string>("UnitType");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("ConversionUnits");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.Currency", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
b.Property<long>("Amount");
|
||||||
|
|
||||||
|
b.Property<ulong>("UserId");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("UserId")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.ToTable("Currency");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("NadekoBot.Services.Database.Models.Donator", b =>
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.Donator", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
@ -136,7 +173,31 @@ namespace NadekoBot.Migrations
|
|||||||
|
|
||||||
b.HasIndex("BotConfigId");
|
b.HasIndex("BotConfigId");
|
||||||
|
|
||||||
b.ToTable("EightBallResponse");
|
b.ToTable("EightBallResponses");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.FollowedStream", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
b.Property<ulong>("ChannelId");
|
||||||
|
|
||||||
|
b.Property<int?>("GuildConfigId");
|
||||||
|
|
||||||
|
b.Property<ulong>("GuildId");
|
||||||
|
|
||||||
|
b.Property<bool>("LastStatus");
|
||||||
|
|
||||||
|
b.Property<int>("Type");
|
||||||
|
|
||||||
|
b.Property<string>("Username");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("GuildConfigId");
|
||||||
|
|
||||||
|
b.ToTable("FollowedStream");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("NadekoBot.Services.Database.Models.GuildConfig", b =>
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.GuildConfig", b =>
|
||||||
@ -160,36 +221,122 @@ namespace NadekoBot.Migrations
|
|||||||
|
|
||||||
b.Property<string>("ChannelGreetMessageText");
|
b.Property<string>("ChannelGreetMessageText");
|
||||||
|
|
||||||
|
b.Property<float>("DefaultMusicVolume");
|
||||||
|
|
||||||
b.Property<bool>("DeleteMessageOnCommand");
|
b.Property<bool>("DeleteMessageOnCommand");
|
||||||
|
|
||||||
b.Property<string>("DmGreetMessageText");
|
b.Property<string>("DmGreetMessageText");
|
||||||
|
|
||||||
b.Property<bool>("ExclusiveSelfAssignedRoles");
|
b.Property<bool>("ExclusiveSelfAssignedRoles");
|
||||||
|
|
||||||
|
b.Property<ulong?>("GenerateCurrencyChannelId");
|
||||||
|
|
||||||
b.Property<ulong>("GreetMessageChannelId");
|
b.Property<ulong>("GreetMessageChannelId");
|
||||||
|
|
||||||
b.Property<ulong>("GuildId");
|
b.Property<ulong>("GuildId");
|
||||||
|
|
||||||
|
b.Property<int?>("LogSettingId");
|
||||||
|
|
||||||
b.Property<bool>("SendChannelByeMessage");
|
b.Property<bool>("SendChannelByeMessage");
|
||||||
|
|
||||||
b.Property<bool>("SendChannelGreetMessage");
|
b.Property<bool>("SendChannelGreetMessage");
|
||||||
|
|
||||||
b.Property<bool>("SendDmGreetMessage");
|
b.Property<bool>("SendDmGreetMessage");
|
||||||
|
|
||||||
|
b.Property<bool>("VoicePlusTextEnabled");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.HasIndex("GuildId")
|
b.HasIndex("GuildId")
|
||||||
.IsUnique();
|
.IsUnique();
|
||||||
|
|
||||||
|
b.HasIndex("LogSettingId");
|
||||||
|
|
||||||
b.ToTable("GuildConfigs");
|
b.ToTable("GuildConfigs");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.IgnoredLogChannel", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
b.Property<ulong>("ChannelId");
|
||||||
|
|
||||||
|
b.Property<int?>("LogSettingId");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("LogSettingId");
|
||||||
|
|
||||||
|
b.ToTable("IgnoredLogChannels");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.IgnoredVoicePresenceChannel", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
b.Property<ulong>("ChannelId");
|
||||||
|
|
||||||
|
b.Property<int?>("LogSettingId");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("LogSettingId");
|
||||||
|
|
||||||
|
b.ToTable("IgnoredVoicePresenceCHannels");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.LogSetting", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
b.Property<bool>("ChannelCreated");
|
||||||
|
|
||||||
|
b.Property<bool>("ChannelDestroyed");
|
||||||
|
|
||||||
|
b.Property<ulong>("ChannelId");
|
||||||
|
|
||||||
|
b.Property<bool>("ChannelUpdated");
|
||||||
|
|
||||||
|
b.Property<bool>("IsLogging");
|
||||||
|
|
||||||
|
b.Property<bool>("LogUserPresence");
|
||||||
|
|
||||||
|
b.Property<bool>("LogVoicePresence");
|
||||||
|
|
||||||
|
b.Property<bool>("MessageDeleted");
|
||||||
|
|
||||||
|
b.Property<bool>("MessageReceived");
|
||||||
|
|
||||||
|
b.Property<bool>("MessageUpdated");
|
||||||
|
|
||||||
|
b.Property<bool>("UserBanned");
|
||||||
|
|
||||||
|
b.Property<bool>("UserJoined");
|
||||||
|
|
||||||
|
b.Property<bool>("UserLeft");
|
||||||
|
|
||||||
|
b.Property<ulong>("UserPresenceChannelId");
|
||||||
|
|
||||||
|
b.Property<bool>("UserUnbanned");
|
||||||
|
|
||||||
|
b.Property<bool>("UserUpdated");
|
||||||
|
|
||||||
|
b.Property<ulong>("VoicePresenceChannelId");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("LogSettings");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("NadekoBot.Services.Database.Models.ModulePrefix", b =>
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.ModulePrefix", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
.ValueGeneratedOnAdd();
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
b.Property<int?>("BotConfigId");
|
b.Property<int>("BotConfigId");
|
||||||
|
|
||||||
b.Property<string>("ModuleName");
|
b.Property<string>("ModuleName");
|
||||||
|
|
||||||
@ -199,7 +346,7 @@ namespace NadekoBot.Migrations
|
|||||||
|
|
||||||
b.HasIndex("BotConfigId");
|
b.HasIndex("BotConfigId");
|
||||||
|
|
||||||
b.ToTable("ModulePrefix");
|
b.ToTable("ModulePrefixes");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("NadekoBot.Services.Database.Models.PlayingStatus", b =>
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.PlayingStatus", b =>
|
||||||
@ -256,7 +403,7 @@ namespace NadekoBot.Migrations
|
|||||||
|
|
||||||
b.HasIndex("BotConfigId");
|
b.HasIndex("BotConfigId");
|
||||||
|
|
||||||
b.ToTable("RaceAnimal");
|
b.ToTable("RaceAnimals");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("NadekoBot.Services.Database.Models.Reminder", b =>
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.Reminder", b =>
|
||||||
@ -281,6 +428,27 @@ namespace NadekoBot.Migrations
|
|||||||
b.ToTable("Reminders");
|
b.ToTable("Reminders");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.Repeater", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
b.Property<ulong>("ChannelId");
|
||||||
|
|
||||||
|
b.Property<ulong>("GuildId");
|
||||||
|
|
||||||
|
b.Property<TimeSpan>("Interval");
|
||||||
|
|
||||||
|
b.Property<string>("Message");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("ChannelId")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.ToTable("Repeaters");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("NadekoBot.Services.Database.Models.SelfAssignedRole", b =>
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.SelfAssignedRole", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
@ -298,6 +466,20 @@ namespace NadekoBot.Migrations
|
|||||||
b.ToTable("SelfAssignableRoles");
|
b.ToTable("SelfAssignableRoles");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.TypingArticle", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
b.Property<string>("Author");
|
||||||
|
|
||||||
|
b.Property<string>("Text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("TypingArticles");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("NadekoBot.Services.Database.Models.BlacklistItem", b =>
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.BlacklistItem", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("NadekoBot.Services.Database.Models.BotConfig")
|
b.HasOne("NadekoBot.Services.Database.Models.BotConfig")
|
||||||
@ -320,11 +502,40 @@ namespace NadekoBot.Migrations
|
|||||||
.HasForeignKey("BotConfigId");
|
.HasForeignKey("BotConfigId");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.FollowedStream", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("NadekoBot.Services.Database.Models.GuildConfig")
|
||||||
|
.WithMany("FollowedStreams")
|
||||||
|
.HasForeignKey("GuildConfigId");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.GuildConfig", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("NadekoBot.Services.Database.Models.LogSetting", "LogSetting")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("LogSettingId");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.IgnoredLogChannel", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("NadekoBot.Services.Database.Models.LogSetting", "LogSetting")
|
||||||
|
.WithMany("IgnoredChannels")
|
||||||
|
.HasForeignKey("LogSettingId");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.IgnoredVoicePresenceChannel", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("NadekoBot.Services.Database.Models.LogSetting", "LogSetting")
|
||||||
|
.WithMany("IgnoredVoicePresenceChannelIds")
|
||||||
|
.HasForeignKey("LogSettingId");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("NadekoBot.Services.Database.Models.ModulePrefix", b =>
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.ModulePrefix", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("NadekoBot.Services.Database.Models.BotConfig")
|
b.HasOne("NadekoBot.Services.Database.Models.BotConfig", "BotConfig")
|
||||||
.WithMany("ModulePrefixes")
|
.WithMany("ModulePrefixes")
|
||||||
.HasForeignKey("BotConfigId");
|
.HasForeignKey("BotConfigId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("NadekoBot.Services.Database.Models.PlayingStatus", b =>
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.PlayingStatus", b =>
|
@ -15,6 +15,8 @@ namespace NadekoBot.Migrations
|
|||||||
Id = table.Column<int>(nullable: false)
|
Id = table.Column<int>(nullable: false)
|
||||||
.Annotation("Autoincrement", true),
|
.Annotation("Autoincrement", true),
|
||||||
BufferSize = table.Column<ulong>(nullable: false),
|
BufferSize = table.Column<ulong>(nullable: false),
|
||||||
|
CurrencyGenerationChance = table.Column<float>(nullable: false),
|
||||||
|
CurrencyGenerationCooldown = table.Column<int>(nullable: false),
|
||||||
CurrencyName = table.Column<string>(nullable: true),
|
CurrencyName = table.Column<string>(nullable: true),
|
||||||
CurrencyPluralName = table.Column<string>(nullable: true),
|
CurrencyPluralName = table.Column<string>(nullable: true),
|
||||||
CurrencySign = table.Column<string>(nullable: true),
|
CurrencySign = table.Column<string>(nullable: true),
|
||||||
@ -47,6 +49,35 @@ namespace NadekoBot.Migrations
|
|||||||
table.PrimaryKey("PK_ClashOfClans", x => x.Id);
|
table.PrimaryKey("PK_ClashOfClans", x => x.Id);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "ConversionUnits",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(nullable: false)
|
||||||
|
.Annotation("Autoincrement", true),
|
||||||
|
InternalTrigger = table.Column<string>(nullable: true),
|
||||||
|
Modifier = table.Column<decimal>(nullable: false),
|
||||||
|
UnitType = table.Column<string>(nullable: true)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_ConversionUnits", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Currency",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(nullable: false)
|
||||||
|
.Annotation("Autoincrement", true),
|
||||||
|
Amount = table.Column<long>(nullable: false),
|
||||||
|
UserId = table.Column<ulong>(nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Currency", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateTable(
|
||||||
name: "Donators",
|
name: "Donators",
|
||||||
columns: table => new
|
columns: table => new
|
||||||
@ -63,31 +94,32 @@ namespace NadekoBot.Migrations
|
|||||||
});
|
});
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateTable(
|
||||||
name: "GuildConfigs",
|
name: "LogSettings",
|
||||||
columns: table => new
|
columns: table => new
|
||||||
{
|
{
|
||||||
Id = table.Column<int>(nullable: false)
|
Id = table.Column<int>(nullable: false)
|
||||||
.Annotation("Autoincrement", true),
|
.Annotation("Autoincrement", true),
|
||||||
AutoAssignRoleId = table.Column<ulong>(nullable: false),
|
ChannelCreated = table.Column<bool>(nullable: false),
|
||||||
AutoDeleteByeMessages = table.Column<bool>(nullable: false),
|
ChannelDestroyed = table.Column<bool>(nullable: false),
|
||||||
AutoDeleteGreetMessages = table.Column<bool>(nullable: false),
|
ChannelId = table.Column<ulong>(nullable: false),
|
||||||
AutoDeleteGreetMessagesTimer = table.Column<int>(nullable: false),
|
ChannelUpdated = table.Column<bool>(nullable: false),
|
||||||
AutoDeleteSelfAssignedRoleMessages = table.Column<bool>(nullable: false),
|
IsLogging = table.Column<bool>(nullable: false),
|
||||||
ByeMessageChannelId = table.Column<ulong>(nullable: false),
|
LogUserPresence = table.Column<bool>(nullable: false),
|
||||||
ChannelByeMessageText = table.Column<string>(nullable: true),
|
LogVoicePresence = table.Column<bool>(nullable: false),
|
||||||
ChannelGreetMessageText = table.Column<string>(nullable: true),
|
MessageDeleted = table.Column<bool>(nullable: false),
|
||||||
DeleteMessageOnCommand = table.Column<bool>(nullable: false),
|
MessageReceived = table.Column<bool>(nullable: false),
|
||||||
DmGreetMessageText = table.Column<string>(nullable: true),
|
MessageUpdated = table.Column<bool>(nullable: false),
|
||||||
ExclusiveSelfAssignedRoles = table.Column<bool>(nullable: false),
|
UserBanned = table.Column<bool>(nullable: false),
|
||||||
GreetMessageChannelId = table.Column<ulong>(nullable: false),
|
UserJoined = table.Column<bool>(nullable: false),
|
||||||
GuildId = table.Column<ulong>(nullable: false),
|
UserLeft = table.Column<bool>(nullable: false),
|
||||||
SendChannelByeMessage = table.Column<bool>(nullable: false),
|
UserPresenceChannelId = table.Column<ulong>(nullable: false),
|
||||||
SendChannelGreetMessage = table.Column<bool>(nullable: false),
|
UserUnbanned = table.Column<bool>(nullable: false),
|
||||||
SendDmGreetMessage = table.Column<bool>(nullable: false)
|
UserUpdated = table.Column<bool>(nullable: false),
|
||||||
|
VoicePresenceChannelId = table.Column<ulong>(nullable: false)
|
||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table =>
|
||||||
{
|
{
|
||||||
table.PrimaryKey("PK_GuildConfigs", x => x.Id);
|
table.PrimaryKey("PK_LogSettings", x => x.Id);
|
||||||
});
|
});
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateTable(
|
||||||
@ -125,6 +157,22 @@ namespace NadekoBot.Migrations
|
|||||||
table.PrimaryKey("PK_Reminders", x => x.Id);
|
table.PrimaryKey("PK_Reminders", x => x.Id);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Repeaters",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(nullable: false)
|
||||||
|
.Annotation("Autoincrement", true),
|
||||||
|
ChannelId = table.Column<ulong>(nullable: false),
|
||||||
|
GuildId = table.Column<ulong>(nullable: false),
|
||||||
|
Interval = table.Column<TimeSpan>(nullable: false),
|
||||||
|
Message = table.Column<string>(nullable: true)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Repeaters", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateTable(
|
||||||
name: "SelfAssignableRoles",
|
name: "SelfAssignableRoles",
|
||||||
columns: table => new
|
columns: table => new
|
||||||
@ -139,6 +187,20 @@ namespace NadekoBot.Migrations
|
|||||||
table.PrimaryKey("PK_SelfAssignableRoles", x => x.Id);
|
table.PrimaryKey("PK_SelfAssignableRoles", x => x.Id);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "TypingArticles",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(nullable: false)
|
||||||
|
.Annotation("Autoincrement", true),
|
||||||
|
Author = table.Column<string>(nullable: true),
|
||||||
|
Text = table.Column<string>(nullable: true)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_TypingArticles", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateTable(
|
||||||
name: "BlacklistItem",
|
name: "BlacklistItem",
|
||||||
columns: table => new
|
columns: table => new
|
||||||
@ -160,7 +222,7 @@ namespace NadekoBot.Migrations
|
|||||||
});
|
});
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateTable(
|
||||||
name: "EightBallResponse",
|
name: "EightBallResponses",
|
||||||
columns: table => new
|
columns: table => new
|
||||||
{
|
{
|
||||||
Id = table.Column<int>(nullable: false)
|
Id = table.Column<int>(nullable: false)
|
||||||
@ -170,9 +232,9 @@ namespace NadekoBot.Migrations
|
|||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table =>
|
||||||
{
|
{
|
||||||
table.PrimaryKey("PK_EightBallResponse", x => x.Id);
|
table.PrimaryKey("PK_EightBallResponses", x => x.Id);
|
||||||
table.ForeignKey(
|
table.ForeignKey(
|
||||||
name: "FK_EightBallResponse_BotConfig_BotConfigId",
|
name: "FK_EightBallResponses_BotConfig_BotConfigId",
|
||||||
column: x => x.BotConfigId,
|
column: x => x.BotConfigId,
|
||||||
principalTable: "BotConfig",
|
principalTable: "BotConfig",
|
||||||
principalColumn: "Id",
|
principalColumn: "Id",
|
||||||
@ -180,24 +242,24 @@ namespace NadekoBot.Migrations
|
|||||||
});
|
});
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateTable(
|
||||||
name: "ModulePrefix",
|
name: "ModulePrefixes",
|
||||||
columns: table => new
|
columns: table => new
|
||||||
{
|
{
|
||||||
Id = table.Column<int>(nullable: false)
|
Id = table.Column<int>(nullable: false)
|
||||||
.Annotation("Autoincrement", true),
|
.Annotation("Autoincrement", true),
|
||||||
BotConfigId = table.Column<int>(nullable: true),
|
BotConfigId = table.Column<int>(nullable: false),
|
||||||
ModuleName = table.Column<string>(nullable: true),
|
ModuleName = table.Column<string>(nullable: true),
|
||||||
Prefix = table.Column<string>(nullable: true)
|
Prefix = table.Column<string>(nullable: true)
|
||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table =>
|
||||||
{
|
{
|
||||||
table.PrimaryKey("PK_ModulePrefix", x => x.Id);
|
table.PrimaryKey("PK_ModulePrefixes", x => x.Id);
|
||||||
table.ForeignKey(
|
table.ForeignKey(
|
||||||
name: "FK_ModulePrefix_BotConfig_BotConfigId",
|
name: "FK_ModulePrefixes_BotConfig_BotConfigId",
|
||||||
column: x => x.BotConfigId,
|
column: x => x.BotConfigId,
|
||||||
principalTable: "BotConfig",
|
principalTable: "BotConfig",
|
||||||
principalColumn: "Id",
|
principalColumn: "Id",
|
||||||
onDelete: ReferentialAction.Restrict);
|
onDelete: ReferentialAction.Cascade);
|
||||||
});
|
});
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateTable(
|
||||||
@ -221,7 +283,7 @@ namespace NadekoBot.Migrations
|
|||||||
});
|
});
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateTable(
|
||||||
name: "RaceAnimal",
|
name: "RaceAnimals",
|
||||||
columns: table => new
|
columns: table => new
|
||||||
{
|
{
|
||||||
Id = table.Column<int>(nullable: false)
|
Id = table.Column<int>(nullable: false)
|
||||||
@ -232,9 +294,9 @@ namespace NadekoBot.Migrations
|
|||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table =>
|
||||||
{
|
{
|
||||||
table.PrimaryKey("PK_RaceAnimal", x => x.Id);
|
table.PrimaryKey("PK_RaceAnimals", x => x.Id);
|
||||||
table.ForeignKey(
|
table.ForeignKey(
|
||||||
name: "FK_RaceAnimal_BotConfig_BotConfigId",
|
name: "FK_RaceAnimals_BotConfig_BotConfigId",
|
||||||
column: x => x.BotConfigId,
|
column: x => x.BotConfigId,
|
||||||
principalTable: "BotConfig",
|
principalTable: "BotConfig",
|
||||||
principalColumn: "Id",
|
principalColumn: "Id",
|
||||||
@ -264,6 +326,108 @@ namespace NadekoBot.Migrations
|
|||||||
onDelete: ReferentialAction.Cascade);
|
onDelete: ReferentialAction.Cascade);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "GuildConfigs",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(nullable: false)
|
||||||
|
.Annotation("Autoincrement", true),
|
||||||
|
AutoAssignRoleId = table.Column<ulong>(nullable: false),
|
||||||
|
AutoDeleteByeMessages = table.Column<bool>(nullable: false),
|
||||||
|
AutoDeleteGreetMessages = table.Column<bool>(nullable: false),
|
||||||
|
AutoDeleteGreetMessagesTimer = table.Column<int>(nullable: false),
|
||||||
|
AutoDeleteSelfAssignedRoleMessages = table.Column<bool>(nullable: false),
|
||||||
|
ByeMessageChannelId = table.Column<ulong>(nullable: false),
|
||||||
|
ChannelByeMessageText = table.Column<string>(nullable: true),
|
||||||
|
ChannelGreetMessageText = table.Column<string>(nullable: true),
|
||||||
|
DefaultMusicVolume = table.Column<float>(nullable: false),
|
||||||
|
DeleteMessageOnCommand = table.Column<bool>(nullable: false),
|
||||||
|
DmGreetMessageText = table.Column<string>(nullable: true),
|
||||||
|
ExclusiveSelfAssignedRoles = table.Column<bool>(nullable: false),
|
||||||
|
GenerateCurrencyChannelId = table.Column<ulong>(nullable: true),
|
||||||
|
GreetMessageChannelId = table.Column<ulong>(nullable: false),
|
||||||
|
GuildId = table.Column<ulong>(nullable: false),
|
||||||
|
LogSettingId = table.Column<int>(nullable: true),
|
||||||
|
SendChannelByeMessage = table.Column<bool>(nullable: false),
|
||||||
|
SendChannelGreetMessage = table.Column<bool>(nullable: false),
|
||||||
|
SendDmGreetMessage = table.Column<bool>(nullable: false),
|
||||||
|
VoicePlusTextEnabled = table.Column<bool>(nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_GuildConfigs", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_GuildConfigs_LogSettings_LogSettingId",
|
||||||
|
column: x => x.LogSettingId,
|
||||||
|
principalTable: "LogSettings",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Restrict);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "IgnoredLogChannels",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(nullable: false)
|
||||||
|
.Annotation("Autoincrement", true),
|
||||||
|
ChannelId = table.Column<ulong>(nullable: false),
|
||||||
|
LogSettingId = table.Column<int>(nullable: true)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_IgnoredLogChannels", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_IgnoredLogChannels_LogSettings_LogSettingId",
|
||||||
|
column: x => x.LogSettingId,
|
||||||
|
principalTable: "LogSettings",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Restrict);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "IgnoredVoicePresenceCHannels",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(nullable: false)
|
||||||
|
.Annotation("Autoincrement", true),
|
||||||
|
ChannelId = table.Column<ulong>(nullable: false),
|
||||||
|
LogSettingId = table.Column<int>(nullable: true)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_IgnoredVoicePresenceCHannels", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_IgnoredVoicePresenceCHannels_LogSettings_LogSettingId",
|
||||||
|
column: x => x.LogSettingId,
|
||||||
|
principalTable: "LogSettings",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Restrict);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "FollowedStream",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(nullable: false)
|
||||||
|
.Annotation("Autoincrement", true),
|
||||||
|
ChannelId = table.Column<ulong>(nullable: false),
|
||||||
|
GuildConfigId = table.Column<int>(nullable: true),
|
||||||
|
GuildId = table.Column<ulong>(nullable: false),
|
||||||
|
LastStatus = table.Column<bool>(nullable: false),
|
||||||
|
Type = table.Column<int>(nullable: false),
|
||||||
|
Username = table.Column<string>(nullable: true)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_FollowedStream", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_FollowedStream_GuildConfigs_GuildConfigId",
|
||||||
|
column: x => x.GuildConfigId,
|
||||||
|
principalTable: "GuildConfigs",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Restrict);
|
||||||
|
});
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.CreateIndex(
|
||||||
name: "IX_BlacklistItem_BotConfigId",
|
name: "IX_BlacklistItem_BotConfigId",
|
||||||
table: "BlacklistItem",
|
table: "BlacklistItem",
|
||||||
@ -274,6 +438,12 @@ namespace NadekoBot.Migrations
|
|||||||
table: "ClashCallers",
|
table: "ClashCallers",
|
||||||
column: "ClashWarId");
|
column: "ClashWarId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Currency_UserId",
|
||||||
|
table: "Currency",
|
||||||
|
column: "UserId",
|
||||||
|
unique: true);
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.CreateIndex(
|
||||||
name: "IX_Donators_UserId",
|
name: "IX_Donators_UserId",
|
||||||
table: "Donators",
|
table: "Donators",
|
||||||
@ -281,10 +451,15 @@ namespace NadekoBot.Migrations
|
|||||||
unique: true);
|
unique: true);
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.CreateIndex(
|
||||||
name: "IX_EightBallResponse_BotConfigId",
|
name: "IX_EightBallResponses_BotConfigId",
|
||||||
table: "EightBallResponse",
|
table: "EightBallResponses",
|
||||||
column: "BotConfigId");
|
column: "BotConfigId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_FollowedStream_GuildConfigId",
|
||||||
|
table: "FollowedStream",
|
||||||
|
column: "GuildConfigId");
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.CreateIndex(
|
||||||
name: "IX_GuildConfigs_GuildId",
|
name: "IX_GuildConfigs_GuildId",
|
||||||
table: "GuildConfigs",
|
table: "GuildConfigs",
|
||||||
@ -292,8 +467,23 @@ namespace NadekoBot.Migrations
|
|||||||
unique: true);
|
unique: true);
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.CreateIndex(
|
||||||
name: "IX_ModulePrefix_BotConfigId",
|
name: "IX_GuildConfigs_LogSettingId",
|
||||||
table: "ModulePrefix",
|
table: "GuildConfigs",
|
||||||
|
column: "LogSettingId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_IgnoredLogChannels_LogSettingId",
|
||||||
|
table: "IgnoredLogChannels",
|
||||||
|
column: "LogSettingId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_IgnoredVoicePresenceCHannels_LogSettingId",
|
||||||
|
table: "IgnoredVoicePresenceCHannels",
|
||||||
|
column: "LogSettingId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_ModulePrefixes_BotConfigId",
|
||||||
|
table: "ModulePrefixes",
|
||||||
column: "BotConfigId");
|
column: "BotConfigId");
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.CreateIndex(
|
||||||
@ -302,10 +492,16 @@ namespace NadekoBot.Migrations
|
|||||||
column: "BotConfigId");
|
column: "BotConfigId");
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.CreateIndex(
|
||||||
name: "IX_RaceAnimal_BotConfigId",
|
name: "IX_RaceAnimals_BotConfigId",
|
||||||
table: "RaceAnimal",
|
table: "RaceAnimals",
|
||||||
column: "BotConfigId");
|
column: "BotConfigId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Repeaters_ChannelId",
|
||||||
|
table: "Repeaters",
|
||||||
|
column: "ChannelId",
|
||||||
|
unique: true);
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.CreateIndex(
|
||||||
name: "IX_SelfAssignableRoles_GuildId_RoleId",
|
name: "IX_SelfAssignableRoles_GuildId_RoleId",
|
||||||
table: "SelfAssignableRoles",
|
table: "SelfAssignableRoles",
|
||||||
@ -321,17 +517,29 @@ namespace NadekoBot.Migrations
|
|||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "ClashCallers");
|
name: "ClashCallers");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "ConversionUnits");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Currency");
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "Donators");
|
name: "Donators");
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "EightBallResponse");
|
name: "EightBallResponses");
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "GuildConfigs");
|
name: "FollowedStream");
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "ModulePrefix");
|
name: "IgnoredLogChannels");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "IgnoredVoicePresenceCHannels");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "ModulePrefixes");
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "PlayingStatus");
|
name: "PlayingStatus");
|
||||||
@ -340,19 +548,31 @@ namespace NadekoBot.Migrations
|
|||||||
name: "Quotes");
|
name: "Quotes");
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "RaceAnimal");
|
name: "RaceAnimals");
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "Reminders");
|
name: "Reminders");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Repeaters");
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "SelfAssignableRoles");
|
name: "SelfAssignableRoles");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "TypingArticles");
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "ClashOfClans");
|
name: "ClashOfClans");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "GuildConfigs");
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "BotConfig");
|
name: "BotConfig");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "LogSettings");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -38,6 +38,10 @@ namespace NadekoBot.Migrations
|
|||||||
|
|
||||||
b.Property<ulong>("BufferSize");
|
b.Property<ulong>("BufferSize");
|
||||||
|
|
||||||
|
b.Property<float>("CurrencyGenerationChance");
|
||||||
|
|
||||||
|
b.Property<int>("CurrencyGenerationCooldown");
|
||||||
|
|
||||||
b.Property<string>("CurrencyName");
|
b.Property<string>("CurrencyName");
|
||||||
|
|
||||||
b.Property<string>("CurrencyPluralName");
|
b.Property<string>("CurrencyPluralName");
|
||||||
@ -103,6 +107,39 @@ namespace NadekoBot.Migrations
|
|||||||
b.ToTable("ClashOfClans");
|
b.ToTable("ClashOfClans");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.ConvertUnit", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
b.Property<string>("InternalTrigger");
|
||||||
|
|
||||||
|
b.Property<decimal>("Modifier");
|
||||||
|
|
||||||
|
b.Property<string>("UnitType");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("ConversionUnits");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.Currency", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
b.Property<long>("Amount");
|
||||||
|
|
||||||
|
b.Property<ulong>("UserId");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("UserId")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.ToTable("Currency");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("NadekoBot.Services.Database.Models.Donator", b =>
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.Donator", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
@ -135,7 +172,31 @@ namespace NadekoBot.Migrations
|
|||||||
|
|
||||||
b.HasIndex("BotConfigId");
|
b.HasIndex("BotConfigId");
|
||||||
|
|
||||||
b.ToTable("EightBallResponse");
|
b.ToTable("EightBallResponses");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.FollowedStream", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
b.Property<ulong>("ChannelId");
|
||||||
|
|
||||||
|
b.Property<int?>("GuildConfigId");
|
||||||
|
|
||||||
|
b.Property<ulong>("GuildId");
|
||||||
|
|
||||||
|
b.Property<bool>("LastStatus");
|
||||||
|
|
||||||
|
b.Property<int>("Type");
|
||||||
|
|
||||||
|
b.Property<string>("Username");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("GuildConfigId");
|
||||||
|
|
||||||
|
b.ToTable("FollowedStream");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("NadekoBot.Services.Database.Models.GuildConfig", b =>
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.GuildConfig", b =>
|
||||||
@ -159,36 +220,122 @@ namespace NadekoBot.Migrations
|
|||||||
|
|
||||||
b.Property<string>("ChannelGreetMessageText");
|
b.Property<string>("ChannelGreetMessageText");
|
||||||
|
|
||||||
|
b.Property<float>("DefaultMusicVolume");
|
||||||
|
|
||||||
b.Property<bool>("DeleteMessageOnCommand");
|
b.Property<bool>("DeleteMessageOnCommand");
|
||||||
|
|
||||||
b.Property<string>("DmGreetMessageText");
|
b.Property<string>("DmGreetMessageText");
|
||||||
|
|
||||||
b.Property<bool>("ExclusiveSelfAssignedRoles");
|
b.Property<bool>("ExclusiveSelfAssignedRoles");
|
||||||
|
|
||||||
|
b.Property<ulong?>("GenerateCurrencyChannelId");
|
||||||
|
|
||||||
b.Property<ulong>("GreetMessageChannelId");
|
b.Property<ulong>("GreetMessageChannelId");
|
||||||
|
|
||||||
b.Property<ulong>("GuildId");
|
b.Property<ulong>("GuildId");
|
||||||
|
|
||||||
|
b.Property<int?>("LogSettingId");
|
||||||
|
|
||||||
b.Property<bool>("SendChannelByeMessage");
|
b.Property<bool>("SendChannelByeMessage");
|
||||||
|
|
||||||
b.Property<bool>("SendChannelGreetMessage");
|
b.Property<bool>("SendChannelGreetMessage");
|
||||||
|
|
||||||
b.Property<bool>("SendDmGreetMessage");
|
b.Property<bool>("SendDmGreetMessage");
|
||||||
|
|
||||||
|
b.Property<bool>("VoicePlusTextEnabled");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.HasIndex("GuildId")
|
b.HasIndex("GuildId")
|
||||||
.IsUnique();
|
.IsUnique();
|
||||||
|
|
||||||
|
b.HasIndex("LogSettingId");
|
||||||
|
|
||||||
b.ToTable("GuildConfigs");
|
b.ToTable("GuildConfigs");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.IgnoredLogChannel", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
b.Property<ulong>("ChannelId");
|
||||||
|
|
||||||
|
b.Property<int?>("LogSettingId");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("LogSettingId");
|
||||||
|
|
||||||
|
b.ToTable("IgnoredLogChannels");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.IgnoredVoicePresenceChannel", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
b.Property<ulong>("ChannelId");
|
||||||
|
|
||||||
|
b.Property<int?>("LogSettingId");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("LogSettingId");
|
||||||
|
|
||||||
|
b.ToTable("IgnoredVoicePresenceCHannels");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.LogSetting", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
b.Property<bool>("ChannelCreated");
|
||||||
|
|
||||||
|
b.Property<bool>("ChannelDestroyed");
|
||||||
|
|
||||||
|
b.Property<ulong>("ChannelId");
|
||||||
|
|
||||||
|
b.Property<bool>("ChannelUpdated");
|
||||||
|
|
||||||
|
b.Property<bool>("IsLogging");
|
||||||
|
|
||||||
|
b.Property<bool>("LogUserPresence");
|
||||||
|
|
||||||
|
b.Property<bool>("LogVoicePresence");
|
||||||
|
|
||||||
|
b.Property<bool>("MessageDeleted");
|
||||||
|
|
||||||
|
b.Property<bool>("MessageReceived");
|
||||||
|
|
||||||
|
b.Property<bool>("MessageUpdated");
|
||||||
|
|
||||||
|
b.Property<bool>("UserBanned");
|
||||||
|
|
||||||
|
b.Property<bool>("UserJoined");
|
||||||
|
|
||||||
|
b.Property<bool>("UserLeft");
|
||||||
|
|
||||||
|
b.Property<ulong>("UserPresenceChannelId");
|
||||||
|
|
||||||
|
b.Property<bool>("UserUnbanned");
|
||||||
|
|
||||||
|
b.Property<bool>("UserUpdated");
|
||||||
|
|
||||||
|
b.Property<ulong>("VoicePresenceChannelId");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("LogSettings");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("NadekoBot.Services.Database.Models.ModulePrefix", b =>
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.ModulePrefix", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
.ValueGeneratedOnAdd();
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
b.Property<int?>("BotConfigId");
|
b.Property<int>("BotConfigId");
|
||||||
|
|
||||||
b.Property<string>("ModuleName");
|
b.Property<string>("ModuleName");
|
||||||
|
|
||||||
@ -198,7 +345,7 @@ namespace NadekoBot.Migrations
|
|||||||
|
|
||||||
b.HasIndex("BotConfigId");
|
b.HasIndex("BotConfigId");
|
||||||
|
|
||||||
b.ToTable("ModulePrefix");
|
b.ToTable("ModulePrefixes");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("NadekoBot.Services.Database.Models.PlayingStatus", b =>
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.PlayingStatus", b =>
|
||||||
@ -255,7 +402,7 @@ namespace NadekoBot.Migrations
|
|||||||
|
|
||||||
b.HasIndex("BotConfigId");
|
b.HasIndex("BotConfigId");
|
||||||
|
|
||||||
b.ToTable("RaceAnimal");
|
b.ToTable("RaceAnimals");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("NadekoBot.Services.Database.Models.Reminder", b =>
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.Reminder", b =>
|
||||||
@ -280,6 +427,27 @@ namespace NadekoBot.Migrations
|
|||||||
b.ToTable("Reminders");
|
b.ToTable("Reminders");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.Repeater", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
b.Property<ulong>("ChannelId");
|
||||||
|
|
||||||
|
b.Property<ulong>("GuildId");
|
||||||
|
|
||||||
|
b.Property<TimeSpan>("Interval");
|
||||||
|
|
||||||
|
b.Property<string>("Message");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("ChannelId")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.ToTable("Repeaters");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("NadekoBot.Services.Database.Models.SelfAssignedRole", b =>
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.SelfAssignedRole", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
@ -297,6 +465,20 @@ namespace NadekoBot.Migrations
|
|||||||
b.ToTable("SelfAssignableRoles");
|
b.ToTable("SelfAssignableRoles");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.TypingArticle", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
b.Property<string>("Author");
|
||||||
|
|
||||||
|
b.Property<string>("Text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("TypingArticles");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("NadekoBot.Services.Database.Models.BlacklistItem", b =>
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.BlacklistItem", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("NadekoBot.Services.Database.Models.BotConfig")
|
b.HasOne("NadekoBot.Services.Database.Models.BotConfig")
|
||||||
@ -319,11 +501,40 @@ namespace NadekoBot.Migrations
|
|||||||
.HasForeignKey("BotConfigId");
|
.HasForeignKey("BotConfigId");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.FollowedStream", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("NadekoBot.Services.Database.Models.GuildConfig")
|
||||||
|
.WithMany("FollowedStreams")
|
||||||
|
.HasForeignKey("GuildConfigId");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.GuildConfig", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("NadekoBot.Services.Database.Models.LogSetting", "LogSetting")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("LogSettingId");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.IgnoredLogChannel", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("NadekoBot.Services.Database.Models.LogSetting", "LogSetting")
|
||||||
|
.WithMany("IgnoredChannels")
|
||||||
|
.HasForeignKey("LogSettingId");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.IgnoredVoicePresenceChannel", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("NadekoBot.Services.Database.Models.LogSetting", "LogSetting")
|
||||||
|
.WithMany("IgnoredVoicePresenceChannelIds")
|
||||||
|
.HasForeignKey("LogSettingId");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("NadekoBot.Services.Database.Models.ModulePrefix", b =>
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.ModulePrefix", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("NadekoBot.Services.Database.Models.BotConfig")
|
b.HasOne("NadekoBot.Services.Database.Models.BotConfig", "BotConfig")
|
||||||
.WithMany("ModulePrefixes")
|
.WithMany("ModulePrefixes")
|
||||||
.HasForeignKey("BotConfigId");
|
.HasForeignKey("BotConfigId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("NadekoBot.Services.Database.Models.PlayingStatus", b =>
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.PlayingStatus", b =>
|
||||||
|
@ -14,18 +14,41 @@ using Discord.WebSocket;
|
|||||||
using NadekoBot.Services.Database;
|
using NadekoBot.Services.Database;
|
||||||
using NadekoBot.Services.Database.Models;
|
using NadekoBot.Services.Database.Models;
|
||||||
|
|
||||||
//todo fix delmsgoncmd
|
|
||||||
namespace NadekoBot.Modules.Administration
|
namespace NadekoBot.Modules.Administration
|
||||||
{
|
{
|
||||||
[Module(".", AppendSpace = false)]
|
[NadekoModule("Administration", ".")]
|
||||||
public partial class Administration : DiscordModule
|
public partial class Administration : DiscordModule
|
||||||
{
|
{
|
||||||
public Administration(ILocalization loc, CommandService cmds, DiscordSocketClient client) : base(loc, cmds, client)
|
public Administration(ILocalization loc, CommandService cmds, DiscordSocketClient client) : base(loc, cmds, client)
|
||||||
{
|
{
|
||||||
|
NadekoBot.CommandHandler.CommandExecuted += DelMsgOnCmd_Handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async void DelMsgOnCmd_Handler(object sender, CommandExecutedEventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var channel = e.Message.Channel as ITextChannel;
|
||||||
|
if (channel == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
bool shouldDelete;
|
||||||
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
|
{
|
||||||
|
shouldDelete = uow.GuildConfigs.For(channel.Guild.Id).DeleteMessageOnCommand;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shouldDelete)
|
||||||
|
await e.Message.DeleteAsync();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_log.Warn(ex, "Delmsgoncmd errored...");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
////todo owner only
|
////todo owner only
|
||||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
//[RequireContext(ContextType.Guild)]
|
//[RequireContext(ContextType.Guild)]
|
||||||
//public async Task Restart(IUserMessage umsg)
|
//public async Task Restart(IUserMessage umsg)
|
||||||
//{
|
//{
|
||||||
@ -37,7 +60,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
// Environment.Exit(0);
|
// Environment.Exit(0);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[RequirePermission(GuildPermission.Administrator)]
|
[RequirePermission(GuildPermission.Administrator)]
|
||||||
public async Task Delmsgoncmd(IUserMessage umsg)
|
public async Task Delmsgoncmd(IUserMessage umsg)
|
||||||
@ -57,7 +80,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
await channel.SendMessageAsync("❗`Stopped automatic deletion of successfull command invokations.`");
|
await channel.SendMessageAsync("❗`Stopped automatic deletion of successfull command invokations.`");
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[RequirePermission(GuildPermission.ManageRoles)]
|
[RequirePermission(GuildPermission.ManageRoles)]
|
||||||
public async Task Setrole(IUserMessage umsg, IGuildUser usr, [Remainder] IRole role)
|
public async Task Setrole(IUserMessage umsg, IGuildUser usr, [Remainder] IRole role)
|
||||||
@ -75,7 +98,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[RequirePermission(GuildPermission.ManageRoles)]
|
[RequirePermission(GuildPermission.ManageRoles)]
|
||||||
public async Task Removerole(IUserMessage umsg, IGuildUser usr, [Remainder] IRole role)
|
public async Task Removerole(IUserMessage umsg, IGuildUser usr, [Remainder] IRole role)
|
||||||
@ -92,7 +115,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[RequirePermission(GuildPermission.ManageRoles)]
|
[RequirePermission(GuildPermission.ManageRoles)]
|
||||||
public async Task RenameRole(IUserMessage umsg, IRole roleToEdit, string newname)
|
public async Task RenameRole(IUserMessage umsg, IRole roleToEdit, string newname)
|
||||||
@ -114,7 +137,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[RequirePermission(GuildPermission.ManageRoles)]
|
[RequirePermission(GuildPermission.ManageRoles)]
|
||||||
public async Task RemoveAllRoles(IUserMessage umsg, [Remainder] IGuildUser user)
|
public async Task RemoveAllRoles(IUserMessage umsg, [Remainder] IGuildUser user)
|
||||||
@ -132,7 +155,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[RequirePermission(GuildPermission.ManageRoles)]
|
[RequirePermission(GuildPermission.ManageRoles)]
|
||||||
public async Task CreateRole(IUserMessage umsg, [Remainder] string roleName = null)
|
public async Task CreateRole(IUserMessage umsg, [Remainder] string roleName = null)
|
||||||
@ -153,7 +176,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[RequirePermission(GuildPermission.ManageRoles)]
|
[RequirePermission(GuildPermission.ManageRoles)]
|
||||||
public async Task RoleColor(IUserMessage umsg, params string[] args)
|
public async Task RoleColor(IUserMessage umsg, params string[] args)
|
||||||
@ -191,7 +214,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[RequirePermission(GuildPermission.BanMembers)]
|
[RequirePermission(GuildPermission.BanMembers)]
|
||||||
public async Task Ban(IUserMessage umsg, IGuildUser user)
|
public async Task Ban(IUserMessage umsg, IGuildUser user)
|
||||||
@ -218,7 +241,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[RequirePermission(GuildPermission.BanMembers)]
|
[RequirePermission(GuildPermission.BanMembers)]
|
||||||
public async Task Softban(IUserMessage umsg, IGuildUser user, [Remainder] string msg = null)
|
public async Task Softban(IUserMessage umsg, IGuildUser user, [Remainder] string msg = null)
|
||||||
@ -244,7 +267,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Kick(IUserMessage umsg, IGuildUser user, [Remainder] string msg = null)
|
public async Task Kick(IUserMessage umsg, IGuildUser user, [Remainder] string msg = null)
|
||||||
{
|
{
|
||||||
@ -272,7 +295,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[RequirePermission(GuildPermission.MuteMembers)]
|
[RequirePermission(GuildPermission.MuteMembers)]
|
||||||
public async Task Mute(IUserMessage umsg, params IGuildUser[] users)
|
public async Task Mute(IUserMessage umsg, params IGuildUser[] users)
|
||||||
@ -295,7 +318,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[RequirePermission(GuildPermission.MuteMembers)]
|
[RequirePermission(GuildPermission.MuteMembers)]
|
||||||
public async Task Unmute(IUserMessage umsg, params IGuildUser[] users)
|
public async Task Unmute(IUserMessage umsg, params IGuildUser[] users)
|
||||||
@ -318,7 +341,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[RequirePermission(GuildPermission.DeafenMembers)]
|
[RequirePermission(GuildPermission.DeafenMembers)]
|
||||||
public async Task Deafen(IUserMessage umsg, params IGuildUser[] users)
|
public async Task Deafen(IUserMessage umsg, params IGuildUser[] users)
|
||||||
@ -341,7 +364,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[RequirePermission(GuildPermission.DeafenMembers)]
|
[RequirePermission(GuildPermission.DeafenMembers)]
|
||||||
public async Task UnDeafen(IUserMessage umsg, params IGuildUser[] users)
|
public async Task UnDeafen(IUserMessage umsg, params IGuildUser[] users)
|
||||||
@ -364,7 +387,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[RequirePermission(GuildPermission.ManageChannels)]
|
[RequirePermission(GuildPermission.ManageChannels)]
|
||||||
public async Task DelVoiChanl(IUserMessage umsg, [Remainder] IVoiceChannel voiceChannel)
|
public async Task DelVoiChanl(IUserMessage umsg, [Remainder] IVoiceChannel voiceChannel)
|
||||||
@ -373,18 +396,17 @@ namespace NadekoBot.Modules.Administration
|
|||||||
await umsg.Channel.SendMessageAsync($"Removed channel **{voiceChannel.Name}**.").ConfigureAwait(false);
|
await umsg.Channel.SendMessageAsync($"Removed channel **{voiceChannel.Name}**.").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[RequirePermission(GuildPermission.ManageChannels)]
|
[RequirePermission(GuildPermission.ManageChannels)]
|
||||||
public async Task CreatVoiChanl(IUserMessage umsg, [Remainder] string channelName)
|
public async Task CreatVoiChanl(IUserMessage umsg, [Remainder] string channelName)
|
||||||
{
|
{
|
||||||
var channel = (ITextChannel)umsg.Channel;
|
var channel = (ITextChannel)umsg.Channel;
|
||||||
//todo actually print info about created channel
|
|
||||||
var ch = await channel.Guild.CreateVoiceChannelAsync(channelName).ConfigureAwait(false);
|
var ch = await channel.Guild.CreateVoiceChannelAsync(channelName).ConfigureAwait(false);
|
||||||
await channel.SendMessageAsync($"Created voice channel **{ch.Name}**, id `{ch.Id}`.").ConfigureAwait(false);
|
await channel.SendMessageAsync($"Created voice channel **{ch.Name}**, id `{ch.Id}`.").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[RequirePermission(GuildPermission.ManageChannels)]
|
[RequirePermission(GuildPermission.ManageChannels)]
|
||||||
public async Task DelTxtChanl(IUserMessage umsg, [Remainder] ITextChannel channel)
|
public async Task DelTxtChanl(IUserMessage umsg, [Remainder] ITextChannel channel)
|
||||||
@ -393,18 +415,17 @@ namespace NadekoBot.Modules.Administration
|
|||||||
await channel.SendMessageAsync($"Removed text channel **{channel.Name}**, id `{channel.Id}`.").ConfigureAwait(false);
|
await channel.SendMessageAsync($"Removed text channel **{channel.Name}**, id `{channel.Id}`.").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[RequirePermission(GuildPermission.ManageChannels)]
|
[RequirePermission(GuildPermission.ManageChannels)]
|
||||||
public async Task CreaTxtChanl(IUserMessage umsg, [Remainder] string channelName)
|
public async Task CreaTxtChanl(IUserMessage umsg, [Remainder] string channelName)
|
||||||
{
|
{
|
||||||
var channel = (ITextChannel)umsg.Channel;
|
var channel = (ITextChannel)umsg.Channel;
|
||||||
//todo actually print info about created channel
|
|
||||||
var txtCh = await channel.Guild.CreateTextChannelAsync(channelName).ConfigureAwait(false);
|
var txtCh = await channel.Guild.CreateTextChannelAsync(channelName).ConfigureAwait(false);
|
||||||
await channel.SendMessageAsync($"Added text channel **{txtCh.Name}**, id `{txtCh.Id}`.").ConfigureAwait(false);
|
await channel.SendMessageAsync($"Added text channel **{txtCh.Name}**, id `{txtCh.Id}`.").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[RequirePermission(GuildPermission.ManageChannels)]
|
[RequirePermission(GuildPermission.ManageChannels)]
|
||||||
public async Task SetTopic(IUserMessage umsg, [Remainder] string topic = null)
|
public async Task SetTopic(IUserMessage umsg, [Remainder] string topic = null)
|
||||||
@ -415,7 +436,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
await channel.SendMessageAsync(":ok: **New channel topic set.**").ConfigureAwait(false);
|
await channel.SendMessageAsync(":ok: **New channel topic set.**").ConfigureAwait(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[RequirePermission(GuildPermission.ManageChannels)]
|
[RequirePermission(GuildPermission.ManageChannels)]
|
||||||
public async Task SetChanlName(IUserMessage umsg, [Remainder] string name)
|
public async Task SetChanlName(IUserMessage umsg, [Remainder] string name)
|
||||||
@ -428,7 +449,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
|
|
||||||
|
|
||||||
//delets her own messages, no perm required
|
//delets her own messages, no perm required
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Prune(IUserMessage umsg)
|
public async Task Prune(IUserMessage umsg)
|
||||||
{
|
{
|
||||||
@ -441,7 +462,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
}
|
}
|
||||||
|
|
||||||
// prune x
|
// prune x
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[RequirePermission(ChannelPermission.ManageMessages)]
|
[RequirePermission(ChannelPermission.ManageMessages)]
|
||||||
public async Task Prune(IUserMessage msg, int count)
|
public async Task Prune(IUserMessage msg, int count)
|
||||||
@ -460,7 +481,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
}
|
}
|
||||||
|
|
||||||
//prune @user [x]
|
//prune @user [x]
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Prune(IUserMessage msg, IGuildUser user, int count = 100)
|
public async Task Prune(IUserMessage msg, IGuildUser user, int count = 100)
|
||||||
{
|
{
|
||||||
@ -470,7 +491,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
await msg.Channel.DeleteMessagesAsync(enumerable);
|
await msg.Channel.DeleteMessagesAsync(enumerable);
|
||||||
}
|
}
|
||||||
////todo owner only
|
////todo owner only
|
||||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
//[RequireContext(ContextType.Guild)]
|
//[RequireContext(ContextType.Guild)]
|
||||||
//public async Task Die(IUserMessage umsg)
|
//public async Task Die(IUserMessage umsg)
|
||||||
//{
|
//{
|
||||||
@ -482,7 +503,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
//}
|
//}
|
||||||
|
|
||||||
////todo owner only
|
////todo owner only
|
||||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
//[RequireContext(ContextType.Guild)]
|
//[RequireContext(ContextType.Guild)]
|
||||||
//public async Task Setname(IUserMessage umsg, [Remainder] string newName = null)
|
//public async Task Setname(IUserMessage umsg, [Remainder] string newName = null)
|
||||||
//{
|
//{
|
||||||
@ -491,7 +512,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
//}
|
//}
|
||||||
|
|
||||||
////todo owner only
|
////todo owner only
|
||||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
//[RequireContext(ContextType.Guild)]
|
//[RequireContext(ContextType.Guild)]
|
||||||
//public async Task NewAvatar(IUserMessage umsg, [Remainder] string img = null)
|
//public async Task NewAvatar(IUserMessage umsg, [Remainder] string img = null)
|
||||||
//{
|
//{
|
||||||
@ -510,7 +531,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
//}
|
//}
|
||||||
|
|
||||||
////todo owner only
|
////todo owner only
|
||||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
//[RequireContext(ContextType.Guild)]
|
//[RequireContext(ContextType.Guild)]
|
||||||
//public async Task SetGame(IUserMessage umsg, [Remainder] string game = null)
|
//public async Task SetGame(IUserMessage umsg, [Remainder] string game = null)
|
||||||
//{
|
//{
|
||||||
@ -522,7 +543,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
//}
|
//}
|
||||||
|
|
||||||
////todo owner only
|
////todo owner only
|
||||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
//[RequireContext(ContextType.Guild)]
|
//[RequireContext(ContextType.Guild)]
|
||||||
//public async Task Send(IUserMessage umsg, string where, [Remainder] string msg = null)
|
//public async Task Send(IUserMessage umsg, string where, [Remainder] string msg = null)
|
||||||
//{
|
//{
|
||||||
@ -567,7 +588,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
//}
|
//}
|
||||||
|
|
||||||
////todo owner only
|
////todo owner only
|
||||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
//[RequireContext(ContextType.Guild)]
|
//[RequireContext(ContextType.Guild)]
|
||||||
//public async Task Announce(IUserMessage umsg, [Remainder] string message)
|
//public async Task Announce(IUserMessage umsg, [Remainder] string message)
|
||||||
//{
|
//{
|
||||||
@ -582,7 +603,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
//}
|
//}
|
||||||
|
|
||||||
////todo owner only
|
////todo owner only
|
||||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
//[RequireContext(ContextType.Guild)]
|
//[RequireContext(ContextType.Guild)]
|
||||||
//public async Task SaveChat(IUserMessage umsg, int cnt)
|
//public async Task SaveChat(IUserMessage umsg, int cnt)
|
||||||
//{
|
//{
|
||||||
@ -614,7 +635,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
//}
|
//}
|
||||||
|
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[RequirePermission(GuildPermission.MentionEveryone)]
|
[RequirePermission(GuildPermission.MentionEveryone)]
|
||||||
public async Task MentionRole(IUserMessage umsg, params IRole[] roles)
|
public async Task MentionRole(IUserMessage umsg, params IRole[] roles)
|
||||||
@ -639,7 +660,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
await channel.SendMessageAsync(send).ConfigureAwait(false);
|
await channel.SendMessageAsync(send).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Donators(IUserMessage umsg)
|
public async Task Donators(IUserMessage umsg)
|
||||||
{
|
{
|
||||||
@ -655,7 +676,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Donadd(IUserMessage umsg, IUser donator, int amount)
|
public async Task Donadd(IUserMessage umsg, IUser donator, int amount)
|
||||||
{
|
{
|
||||||
|
@ -19,7 +19,9 @@ namespace NadekoBot.Modules.Administration
|
|||||||
public AutoAssignRoleCommands()
|
public AutoAssignRoleCommands()
|
||||||
{
|
{
|
||||||
var _client = NadekoBot.Client;
|
var _client = NadekoBot.Client;
|
||||||
_client.UserJoined += async (user) =>
|
_client.UserJoined += (user) =>
|
||||||
|
{
|
||||||
|
var t = Task.Run(async () =>
|
||||||
{
|
{
|
||||||
GuildConfig conf;
|
GuildConfig conf;
|
||||||
using (var uow = DbHandler.UnitOfWork())
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
@ -35,10 +37,12 @@ namespace NadekoBot.Modules.Administration
|
|||||||
|
|
||||||
if (role != null)
|
if (role != null)
|
||||||
await user.AddRolesAsync(role);
|
await user.AddRolesAsync(role);
|
||||||
|
});
|
||||||
|
return Task.CompletedTask;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[RequirePermission(GuildPermission.ManageRoles)]
|
[RequirePermission(GuildPermission.ManageRoles)]
|
||||||
public async Task AutoAssignRole(IUserMessage umsg, [Remainder] IRole role = null)
|
public async Task AutoAssignRole(IUserMessage umsg, [Remainder] IRole role = null)
|
||||||
|
@ -1,111 +1,102 @@
|
|||||||
//using Discord;
|
using Discord;
|
||||||
//using Discord.Commands;
|
using Discord.Commands;
|
||||||
//using NadekoBot.Classes;
|
using Discord.WebSocket;
|
||||||
//using NadekoBot.Modules.Permissions.Classes;
|
using NadekoBot.Attributes;
|
||||||
//using System;
|
using NadekoBot.Extensions;
|
||||||
//using System.Collections.Concurrent;
|
using System;
|
||||||
//using System.Collections.Generic;
|
using System.Collections.Concurrent;
|
||||||
//using System.Linq;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
////todo DB
|
namespace NadekoBot.Modules.Administration
|
||||||
//namespace NadekoBot.Modules.Administration
|
{
|
||||||
//{
|
public partial class Administration
|
||||||
// class CrossServerTextChannel : DiscordCommand
|
{
|
||||||
// {
|
[Group]
|
||||||
// public CrossServerTextChannel(DiscordModule module) : base(module)
|
public class CrossServerTextChannel
|
||||||
// {
|
{
|
||||||
// NadekoBot.Client.MessageReceived += async (s, e) =>
|
public CrossServerTextChannel()
|
||||||
// {
|
{
|
||||||
// try
|
NadekoBot.Client.MessageReceived += (imsg) =>
|
||||||
// {
|
{
|
||||||
// if (umsg.Author.Id == NadekoBot.Client.CurrentUser.Id) return;
|
var msg = imsg as IUserMessage;
|
||||||
// foreach (var subscriber in Subscribers)
|
if (msg == null)
|
||||||
// {
|
return Task.CompletedTask;
|
||||||
// var set = subscriber.Value;
|
|
||||||
// if (!set.Contains(e.Channel))
|
|
||||||
// continue;
|
|
||||||
// foreach (var chan in set.Except(new[] { e.Channel }))
|
|
||||||
// {
|
|
||||||
// await chan.SendMessageAsync(GetText(e.Server, e.Channel, umsg.Author, e.Message)).ConfigureAwait(false);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// catch { }
|
|
||||||
// };
|
|
||||||
// NadekoBot.Client.MessageUpdated += async (s, e) =>
|
|
||||||
// {
|
|
||||||
// try
|
|
||||||
// {
|
|
||||||
// if (e.After?.User?.Id == null || e.After.User.Id == NadekoBot.Client.CurrentUser.Id) return;
|
|
||||||
// foreach (var subscriber in Subscribers)
|
|
||||||
// {
|
|
||||||
// var set = subscriber.Value;
|
|
||||||
// if (!set.Contains(e.Channel))
|
|
||||||
// continue;
|
|
||||||
// foreach (var chan in set.Except(new[] { e.Channel }))
|
|
||||||
// {
|
|
||||||
// var msg = chan.Messages
|
|
||||||
// .FirstOrDefault(m =>
|
|
||||||
// m.RawText == GetText(e.Server, e.Channel, umsg.Author, e.Before));
|
|
||||||
// if (msg != default(Message))
|
|
||||||
// await msg.Edit(GetText(e.Server, e.Channel, umsg.Author, e.After)).ConfigureAwait(false);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// }
|
var channel = imsg.Channel as ITextChannel;
|
||||||
// catch { }
|
if (channel == null)
|
||||||
// };
|
return Task.CompletedTask;
|
||||||
// }
|
|
||||||
|
|
||||||
// private string GetText(Server server, Channel channel, User user, Message message) =>
|
Task.Run(async () =>
|
||||||
// $"**{server.Name} | {channel.Name}** `{user.Name}`: " + message.RawText;
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (msg.Author.Id == NadekoBot.Client.GetCurrentUser().Id) return;
|
||||||
|
foreach (var subscriber in Subscribers)
|
||||||
|
{
|
||||||
|
var set = subscriber.Value;
|
||||||
|
if (!set.Contains(msg.Channel))
|
||||||
|
continue;
|
||||||
|
foreach (var chan in set.Except(new[] { channel }))
|
||||||
|
{
|
||||||
|
await chan.SendMessageAsync(GetText(channel.Guild, channel, (IGuildUser)msg.Author, msg)).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
});
|
||||||
|
return Task.CompletedTask;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// public static readonly ConcurrentDictionary<int, HashSet<Channel>> Subscribers = new ConcurrentDictionary<int, HashSet<Channel>>();
|
private string GetText(IGuild server, ITextChannel channel, IGuildUser user, IUserMessage message) =>
|
||||||
|
$"**{server.Name} | {channel.Name}** `{user.Username}`: " + message.Content;
|
||||||
|
|
||||||
// internal override void Init(CommandGroupBuilder cgb)
|
public static readonly ConcurrentDictionary<int, HashSet<ITextChannel>> Subscribers = new ConcurrentDictionary<int, HashSet<ITextChannel>>();
|
||||||
|
|
||||||
|
////todo owner only
|
||||||
|
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
|
//[RequireContext(ContextType.Guild)]
|
||||||
|
//public async Task Scsc(IUserMessage msg)
|
||||||
//{
|
//{
|
||||||
// cgb.CreateCommand(Module.Prefix + "scsc")
|
// var channel = (ITextChannel)msg.Channel;
|
||||||
// .Description("Starts an instance of cross server channel. You will get a token as a DM " +
|
// var token = new NadekoRandom().Next();
|
||||||
// $"that other people will use to tune in to the same instance. **Bot Owner Only.** | `{Prefix}scsc`")
|
// var set = new HashSet<ITextChannel>();
|
||||||
// .AddCheck(SimpleCheckers.OwnerOnly())
|
|
||||||
// .Do(async e =>
|
|
||||||
// {
|
|
||||||
// var token = new Random().Next();
|
|
||||||
// var set = new HashSet<Channel>();
|
|
||||||
// if (Subscribers.TryAdd(token, set))
|
// if (Subscribers.TryAdd(token, set))
|
||||||
// {
|
// {
|
||||||
// set.Add(e.Channel);
|
// set.Add(channel);
|
||||||
// await umsg.Author.SendMessageAsync("This is your CSC token:" + token.ToString()).ConfigureAwait(false);
|
// await ((IGuildUser)msg.Author).SendMessageAsync("This is your CSC token:" + token.ToString()).ConfigureAwait(false);
|
||||||
|
// }
|
||||||
//}
|
//}
|
||||||
// });
|
|
||||||
|
|
||||||
// cgb.CreateCommand(Module.Prefix + "jcsc")
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
// .Description($"Joins current channel to an instance of cross server channel using the token. **Needs Manage Server Permissions.**| `{Prefix}jcsc`")
|
[RequireContext(ContextType.Guild)]
|
||||||
// .Parameter("token")
|
[RequirePermission(GuildPermission.ManageGuild)]
|
||||||
// .AddCheck(SimpleCheckers.ManageServer())
|
public async Task Jcsc(IUserMessage imsg, int token)
|
||||||
// .Do(async e =>
|
{
|
||||||
// {
|
var channel = (ITextChannel)imsg.Channel;
|
||||||
// int token;
|
|
||||||
// if (!int.TryParse(token, out token))
|
|
||||||
// return;
|
|
||||||
// HashSet<Channel> set;
|
|
||||||
// if (!Subscribers.TryGetValue(token, out set))
|
|
||||||
// return;
|
|
||||||
// set.Add(e.Channel);
|
|
||||||
// await channel.SendMessageAsync(":ok:").ConfigureAwait(false);
|
|
||||||
// });
|
|
||||||
|
|
||||||
// cgb.CreateCommand(Module.Prefix + "lcsc")
|
HashSet<ITextChannel> set;
|
||||||
// .Description($"Leaves Cross server channel instance from this channel. **Needs Manage Server Permissions.**| `{Prefix}lcsc`")
|
if (!Subscribers.TryGetValue(token, out set))
|
||||||
// .AddCheck(SimpleCheckers.ManageServer())
|
return;
|
||||||
// .Do(async e =>
|
set.Add(channel);
|
||||||
// {
|
await channel.SendMessageAsync(":ok:").ConfigureAwait(false);
|
||||||
// foreach (var subscriber in Subscribers)
|
}
|
||||||
// {
|
|
||||||
// subscriber.Value.Remove(e.Channel);
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
// }
|
[RequireContext(ContextType.Guild)]
|
||||||
// await channel.SendMessageAsync(":ok:").ConfigureAwait(false);
|
[RequirePermission(GuildPermission.ManageGuild)]
|
||||||
// });
|
public async Task Lcsc(IUserMessage imsg)
|
||||||
// }
|
{
|
||||||
// }
|
var channel = (ITextChannel)imsg.Channel;
|
||||||
//}
|
|
||||||
|
foreach (var subscriber in Subscribers)
|
||||||
|
{
|
||||||
|
subscriber.Value.Remove(channel);
|
||||||
|
}
|
||||||
|
await channel.SendMessageAsync(":ok:").ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
@ -1,130 +1,159 @@
|
|||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using NadekoBot.Classes;
|
using Discord.WebSocket;
|
||||||
using NadekoBot.Modules.Permissions.Classes;
|
using NadekoBot.Attributes;
|
||||||
|
using NadekoBot.Services;
|
||||||
|
using NadekoBot.Services.Database;
|
||||||
|
using NadekoBot.Services.Database.Models;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Timers;
|
|
||||||
|
|
||||||
//todo DB
|
|
||||||
namespace NadekoBot.Modules.Administration
|
namespace NadekoBot.Modules.Administration
|
||||||
{
|
{
|
||||||
class MessageRepeater : DiscordCommand
|
public partial class Administration
|
||||||
{
|
{
|
||||||
private readonly ConcurrentDictionary<Server, Repeater> repeaters = new ConcurrentDictionary<Server, Repeater>();
|
[Group]
|
||||||
private class Repeater
|
public class RepeatCommands
|
||||||
{
|
{
|
||||||
[Newtonsoft.Json.JsonIgnore]
|
public ConcurrentDictionary<ulong, RepeatRunner> repeaters;
|
||||||
public Timer MessageTimer { get; set; }
|
|
||||||
[Newtonsoft.Json.JsonIgnore]
|
|
||||||
public Channel RepeatingChannel { get; set; }
|
|
||||||
|
|
||||||
public ulong RepeatingServerId { get; set; }
|
public class RepeatRunner
|
||||||
public ulong RepeatingChannelId { get; set; }
|
|
||||||
public Message lastMessage { get; set; } = null;
|
|
||||||
public string RepeatingMessage { get; set; }
|
|
||||||
public int Interval { get; set; }
|
|
||||||
|
|
||||||
public Repeater Start()
|
|
||||||
{
|
{
|
||||||
MessageTimer = new Timer { Interval = Interval };
|
private CancellationTokenSource source { get; set; }
|
||||||
MessageTimer.Elapsed += async (s, e) => await Invoke();
|
private CancellationToken token { get; set; }
|
||||||
return this;
|
public Repeater Repeater { get; }
|
||||||
|
public ITextChannel Channel { get; }
|
||||||
|
|
||||||
|
public RepeatRunner(Repeater repeater, ITextChannel channel = null)
|
||||||
|
{
|
||||||
|
this.Repeater = repeater;
|
||||||
|
this.Channel = channel ?? NadekoBot.Client.GetGuild(repeater.GuildId)?.GetTextChannel(repeater.ChannelId);
|
||||||
|
if (Channel == null)
|
||||||
|
return;
|
||||||
|
Task.Run(Run);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Invoke()
|
|
||||||
{
|
private async Task Run()
|
||||||
var ch = RepeatingChannel;
|
|
||||||
var msg = RepeatingMessage;
|
|
||||||
if (ch != null && !string.IsNullOrWhiteSpace(msg))
|
|
||||||
{
|
{
|
||||||
|
source = new CancellationTokenSource();
|
||||||
|
token = source.Token;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (lastMessage != null)
|
while (!token.IsCancellationRequested)
|
||||||
await lastMessage.Delete().ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
catch { }
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
lastMessage = await ch.SendMessageAsync(msg).ConfigureAwait(false);
|
await Task.Delay(Repeater.Interval, token).ConfigureAwait(false);
|
||||||
}
|
await Channel.SendMessageAsync("🔄 " + Repeater.Message).ConfigureAwait(false);
|
||||||
catch { }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (OperationCanceledException) { }
|
||||||
}
|
}
|
||||||
internal override void Init(CommandGroupBuilder cgb)
|
|
||||||
{
|
|
||||||
|
|
||||||
cgb.CreateCommand(Module.Prefix + "repeatinvoke")
|
public void Reset()
|
||||||
.Alias(Module.Prefix + "repinv")
|
|
||||||
.Description($"Immediately shows the repeat message and restarts the timer. **Needs Manage Messages Permissions.**| `{Prefix}repinv`")
|
|
||||||
.AddCheck(SimpleCheckers.ManageMessages())
|
|
||||||
.Do(async e =>
|
|
||||||
{
|
{
|
||||||
Repeater rep;
|
source.Cancel();
|
||||||
if (!repeaters.TryGetValue(e.Server, out rep))
|
var t = Task.Run(Run);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Stop()
|
||||||
{
|
{
|
||||||
await channel.SendMessageAsync("`No repeating message found on this server.`");
|
source.Cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public RepeatCommands()
|
||||||
|
{
|
||||||
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
|
{
|
||||||
|
repeaters = new ConcurrentDictionary<ulong, RepeatRunner>(uow.Repeaters.GetAll().Select(r => new RepeatRunner(r)).Where(r => r != null).ToDictionary(r => r.Repeater.ChannelId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
|
[RequireContext(ContextType.Guild)]
|
||||||
|
[RequirePermission(GuildPermission.ManageMessages)]
|
||||||
|
public async Task RepeatInvoke(IUserMessage imsg)
|
||||||
|
{
|
||||||
|
var channel = (ITextChannel)imsg.Channel;
|
||||||
|
|
||||||
|
RepeatRunner rep;
|
||||||
|
if (!repeaters.TryGetValue(channel.Id, out rep))
|
||||||
|
{
|
||||||
|
await channel.SendMessageAsync("`No repeating message found on this server.`").ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
rep.Reset();
|
||||||
|
await channel.SendMessageAsync("🔄 " + rep.Repeater.Message).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
await rep.Invoke();
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
|
[RequireContext(ContextType.Guild)]
|
||||||
|
public async Task Repeat(IUserMessage imsg)
|
||||||
|
{
|
||||||
|
var channel = (ITextChannel)imsg.Channel;
|
||||||
|
RepeatRunner rep;
|
||||||
|
if (repeaters.TryRemove(channel.Id, out rep))
|
||||||
|
{
|
||||||
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
|
{
|
||||||
|
uow.Repeaters.Remove(rep.Repeater);
|
||||||
|
await uow.CompleteAsync();
|
||||||
|
}
|
||||||
|
rep.Stop();
|
||||||
|
await channel.SendMessageAsync("`Stopped repeating a message.`").ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
await channel.SendMessageAsync("`No message is repeating.`").ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
|
[RequireContext(ContextType.Guild)]
|
||||||
|
public async Task Repeat(IUserMessage imsg, int minutes, [Remainder] string message)
|
||||||
|
{
|
||||||
|
var channel = (ITextChannel)imsg.Channel;
|
||||||
|
|
||||||
|
if (minutes < 1 || minutes > 1500)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(message))
|
||||||
|
return;
|
||||||
|
|
||||||
|
RepeatRunner rep;
|
||||||
|
|
||||||
|
rep = repeaters.AddOrUpdate(channel.Id, (cid) =>
|
||||||
|
{
|
||||||
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
|
{
|
||||||
|
var localRep = new Repeater
|
||||||
|
{
|
||||||
|
ChannelId = channel.Id,
|
||||||
|
GuildId = channel.Guild.Id,
|
||||||
|
Interval = TimeSpan.FromMinutes(minutes),
|
||||||
|
Message = message,
|
||||||
|
};
|
||||||
|
uow.Repeaters.Add(localRep);
|
||||||
|
uow.Complete();
|
||||||
|
return new RepeatRunner(localRep, channel);
|
||||||
|
}
|
||||||
|
}, (cid, old) =>
|
||||||
|
{
|
||||||
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
|
{
|
||||||
|
old.Repeater.Message = message;
|
||||||
|
old.Repeater.Interval = TimeSpan.FromMinutes(minutes);
|
||||||
|
uow.Repeaters.Update(old.Repeater);
|
||||||
|
uow.Complete();
|
||||||
|
}
|
||||||
|
old.Reset();
|
||||||
|
return old;
|
||||||
});
|
});
|
||||||
|
|
||||||
cgb.CreateCommand(Module.Prefix + "repeat")
|
await channel.SendMessageAsync($"Repeating \"{rep.Repeater.Message}\" every {rep.Repeater.Interval} minutes").ConfigureAwait(false);
|
||||||
.Description("Repeat a message every X minutes. If no parameters are specified, " +
|
}
|
||||||
$"repeat is disabled. **Needs Manage Messages Permissions.** |`{Prefix}repeat 5 Hello there`")
|
}
|
||||||
.Parameter("minutes", ParameterType.Optional)
|
|
||||||
.Parameter("msg", ParameterType.Unparsed)
|
|
||||||
.AddCheck(SimpleCheckers.ManageMessages())
|
|
||||||
.Do(async e =>
|
|
||||||
{
|
|
||||||
var minutesStr = minutes;
|
|
||||||
var msg = msg;
|
|
||||||
|
|
||||||
// if both null, disable
|
|
||||||
if (string.IsNullOrWhiteSpace(msg) && string.IsNullOrWhiteSpace(minutesStr))
|
|
||||||
{
|
|
||||||
|
|
||||||
Repeater rep;
|
|
||||||
if (!repeaters.TryRemove(e.Server, out rep))
|
|
||||||
return;
|
|
||||||
rep.MessageTimer.Stop();
|
|
||||||
await channel.SendMessageAsync("Repeating disabled").ConfigureAwait(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int minutes;
|
|
||||||
if (!int.TryParse(minutesStr, out minutes) || minutes < 1 || minutes > 1440)
|
|
||||||
{
|
|
||||||
await channel.SendMessageAsync("Invalid value").ConfigureAwait(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var repeater = repeaters.GetOrAdd(
|
|
||||||
e.Server,
|
|
||||||
s => new Repeater
|
|
||||||
{
|
|
||||||
Interval = minutes * 60 * 1000,
|
|
||||||
RepeatingChannel = e.Channel,
|
|
||||||
RepeatingChannelId = e.Channel.Id,
|
|
||||||
RepeatingServerId = e.Server.Id,
|
|
||||||
}.Start()
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(msg))
|
|
||||||
repeater.RepeatingMessage = msg;
|
|
||||||
|
|
||||||
repeater.MessageTimer.Stop();
|
|
||||||
repeater.MessageTimer.Start();
|
|
||||||
|
|
||||||
await channel.SendMessageAsync(String.Format("👌 Repeating `{0}` every " +
|
|
||||||
"**{1}** minutes on {2} channel.",
|
|
||||||
repeater.RepeatingMessage, minutes, repeater.RepeatingChannel))
|
|
||||||
.ConfigureAwait(false);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public MessageRepeater(DiscordModule module) : base(module) { }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -86,7 +86,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
{"%queued%", () => Music.Music.MusicPlayers.Sum(kvp => kvp.Value.Playlist.Count).ToString()}
|
{"%queued%", () => Music.Music.MusicPlayers.Sum(kvp => kvp.Value.Playlist.Count).ToString()}
|
||||||
};
|
};
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task RotatePlaying(IUserMessage umsg)
|
public async Task RotatePlaying(IUserMessage umsg)
|
||||||
{
|
{
|
||||||
@ -106,7 +106,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
await channel.SendMessageAsync("`Rotating playing status disabled.`");
|
await channel.SendMessageAsync("`Rotating playing status disabled.`");
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task AddPlaying(IUserMessage umsg, [Remainder] string status)
|
public async Task AddPlaying(IUserMessage umsg, [Remainder] string status)
|
||||||
{
|
{
|
||||||
@ -122,7 +122,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
await channel.SendMessageAsync("`Added.`").ConfigureAwait(false);
|
await channel.SendMessageAsync("`Added.`").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task ListPlaying(IUserMessage umsg)
|
public async Task ListPlaying(IUserMessage umsg)
|
||||||
{
|
{
|
||||||
@ -144,7 +144,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task RemovePlaying(IUserMessage umsg, int index)
|
public async Task RemovePlaying(IUserMessage umsg, int index)
|
||||||
{
|
{
|
||||||
|
@ -5,9 +5,9 @@ using NadekoBot.Attributes;
|
|||||||
using NadekoBot.Extensions;
|
using NadekoBot.Extensions;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
//todo rewrite to accept msg/sec (for example 1/5 - 1 message every 5 seconds)
|
|
||||||
namespace NadekoBot.Modules.Administration
|
namespace NadekoBot.Modules.Administration
|
||||||
{
|
{
|
||||||
public partial class Administration
|
public partial class Administration
|
||||||
@ -15,58 +15,103 @@ namespace NadekoBot.Modules.Administration
|
|||||||
[Group]
|
[Group]
|
||||||
public class RatelimitCommand
|
public class RatelimitCommand
|
||||||
{
|
{
|
||||||
public static ConcurrentDictionary<ulong, ConcurrentDictionary<ulong, DateTime>> RatelimitingChannels = new ConcurrentDictionary<ulong, ConcurrentDictionary<ulong, DateTime>>();
|
public static ConcurrentDictionary<ulong, Ratelimiter> RatelimitingChannels = new ConcurrentDictionary<ulong, Ratelimiter>();
|
||||||
|
|
||||||
private static readonly TimeSpan ratelimitTime = new TimeSpan(0, 0, 0, 5);
|
|
||||||
private DiscordSocketClient _client { get; }
|
private DiscordSocketClient _client { get; }
|
||||||
|
|
||||||
|
public class Ratelimiter
|
||||||
|
{
|
||||||
|
public class RatelimitedUser
|
||||||
|
{
|
||||||
|
public ulong UserId { get; set; }
|
||||||
|
public int MessageCount { get; set; } = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ulong ChannelId { get; set; }
|
||||||
|
|
||||||
|
public int MaxMessages { get; set; }
|
||||||
|
public int PerSeconds { get; set; }
|
||||||
|
|
||||||
|
public CancellationTokenSource cancelSource { get; set; } = new CancellationTokenSource();
|
||||||
|
|
||||||
|
public ConcurrentDictionary<ulong, RatelimitedUser> Users { get; set; } = new ConcurrentDictionary<ulong, RatelimitedUser>();
|
||||||
|
|
||||||
|
public bool CheckUserRatelimit(ulong id)
|
||||||
|
{
|
||||||
|
RatelimitedUser usr = Users.GetOrAdd(id, (key) => new RatelimitedUser() { UserId = id });
|
||||||
|
if (usr.MessageCount == MaxMessages)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
usr.MessageCount++;
|
||||||
|
var t = Task.Run(async () => {
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await Task.Delay(PerSeconds * 1000, cancelSource.Token);
|
||||||
|
}
|
||||||
|
catch (OperationCanceledException) { }
|
||||||
|
usr.MessageCount--;
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public RatelimitCommand()
|
public RatelimitCommand()
|
||||||
{
|
{
|
||||||
|
|
||||||
this._client = NadekoBot.Client;
|
this._client = NadekoBot.Client;
|
||||||
|
|
||||||
_client.MessageReceived += async (umsg) =>
|
_client.MessageReceived += (umsg) =>
|
||||||
|
{
|
||||||
|
var t = Task.Run(async () =>
|
||||||
{
|
{
|
||||||
var usrMsg = umsg as IUserMessage;
|
var usrMsg = umsg as IUserMessage;
|
||||||
var channel = usrMsg.Channel as ITextChannel;
|
var channel = usrMsg.Channel as ITextChannel;
|
||||||
|
|
||||||
if (channel == null || await usrMsg.IsAuthor())
|
if (channel == null || usrMsg.IsAuthor())
|
||||||
return;
|
return;
|
||||||
ConcurrentDictionary<ulong, DateTime> userTimePair;
|
Ratelimiter limiter;
|
||||||
if (!RatelimitingChannels.TryGetValue(channel.Id, out userTimePair)) return;
|
if (!RatelimitingChannels.TryGetValue(channel.Id, out limiter))
|
||||||
DateTime lastMessageTime;
|
|
||||||
if (userTimePair.TryGetValue(usrMsg.Author.Id, out lastMessageTime))
|
|
||||||
{
|
|
||||||
if (DateTime.Now - lastMessageTime < ratelimitTime)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await usrMsg.DeleteAsync().ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
catch { }
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
}
|
if (limiter.CheckUserRatelimit(usrMsg.Author.Id))
|
||||||
userTimePair.AddOrUpdate(usrMsg.Author.Id, id => DateTime.Now, (id, dt) => DateTime.Now);
|
await usrMsg.DeleteAsync();
|
||||||
|
});
|
||||||
|
return Task.CompletedTask;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Slowmode(IUserMessage umsg)
|
public async Task Slowmode(IUserMessage umsg, int msg = 1, int perSec = 5)
|
||||||
{
|
{
|
||||||
var channel = (ITextChannel)umsg.Channel;
|
var channel = (ITextChannel)umsg.Channel;
|
||||||
|
|
||||||
ConcurrentDictionary<ulong, DateTime> throwaway;
|
Ratelimiter throwaway;
|
||||||
if (RatelimitingChannels.TryRemove(channel.Id, out throwaway))
|
if (RatelimitingChannels.TryRemove(channel.Id, out throwaway))
|
||||||
{
|
{
|
||||||
await channel.SendMessageAsync("Slow mode disabled.").ConfigureAwait(false);
|
throwaway.cancelSource.Cancel();
|
||||||
|
await channel.SendMessageAsync("`Slow mode disabled.`").ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (RatelimitingChannels.TryAdd(channel.Id, new ConcurrentDictionary<ulong, DateTime>()))
|
|
||||||
|
if (msg < 1 || perSec < 1)
|
||||||
{
|
{
|
||||||
await channel.SendMessageAsync("Slow mode initiated. " +
|
await channel.SendMessageAsync("`Invalid parameters.`");
|
||||||
"Users can't send more than 1 message every 5 seconds.")
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (RatelimitingChannels.TryAdd(channel.Id,throwaway = new Ratelimiter() {
|
||||||
|
ChannelId = channel.Id,
|
||||||
|
MaxMessages = msg,
|
||||||
|
PerSeconds = perSec,
|
||||||
|
}))
|
||||||
|
{
|
||||||
|
await channel.SendMessageAsync("`Slow mode initiated.` " +
|
||||||
|
$"Users can't send more than {throwaway.MaxMessages} message(s) every {throwaway.PerSeconds} second(s).")
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
//todo DB
|
|
||||||
namespace NadekoBot.Modules.Administration
|
namespace NadekoBot.Modules.Administration
|
||||||
{
|
{
|
||||||
public partial class Administration
|
public partial class Administration
|
||||||
@ -19,7 +19,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
public class SelfAssignedRolesCommands
|
public class SelfAssignedRolesCommands
|
||||||
{
|
{
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[RequirePermission(GuildPermission.ManageRoles)]
|
[RequirePermission(GuildPermission.ManageRoles)]
|
||||||
public async Task Asar(IUserMessage umsg, [Remainder] IRole role)
|
public async Task Asar(IUserMessage umsg, [Remainder] IRole role)
|
||||||
@ -49,7 +49,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
await channel.SendMessageAsync(msg.ToString()).ConfigureAwait(false);
|
await channel.SendMessageAsync(msg.ToString()).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[RequirePermission(GuildPermission.ManageRoles)]
|
[RequirePermission(GuildPermission.ManageRoles)]
|
||||||
public async Task Rsar(IUserMessage umsg, [Remainder] IRole role)
|
public async Task Rsar(IUserMessage umsg, [Remainder] IRole role)
|
||||||
@ -70,7 +70,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
await channel.SendMessageAsync($":ok:**{role.Name}** has been removed from the list of self-assignable roles").ConfigureAwait(false);
|
await channel.SendMessageAsync($":ok:**{role.Name}** has been removed from the list of self-assignable roles").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Lsar(IUserMessage umsg)
|
public async Task Lsar(IUserMessage umsg)
|
||||||
{
|
{
|
||||||
@ -105,7 +105,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
await channel.SendMessageAsync(msg.ToString() + "\n\n" + removeMsg.ToString()).ConfigureAwait(false);
|
await channel.SendMessageAsync(msg.ToString() + "\n\n" + removeMsg.ToString()).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[RequirePermission(GuildPermission.ManageRoles)]
|
[RequirePermission(GuildPermission.ManageRoles)]
|
||||||
public async Task Tesar(IUserMessage umsg)
|
public async Task Tesar(IUserMessage umsg)
|
||||||
@ -124,7 +124,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
await channel.SendMessageAsync("Self assigned roles are now " + exl);
|
await channel.SendMessageAsync("Self assigned roles are now " + exl);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Iam(IUserMessage umsg, [Remainder] IRole role)
|
public async Task Iam(IUserMessage umsg, [Remainder] IRole role)
|
||||||
{
|
{
|
||||||
@ -182,7 +182,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Iamnot(IUserMessage umsg, [Remainder] IRole role)
|
public async Task Iamnot(IUserMessage umsg, [Remainder] IRole role)
|
||||||
{
|
{
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
// this._client = client;
|
// this._client = client;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// [LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
// [LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
// [RequireContext(ContextType.Guild)]
|
// [RequireContext(ContextType.Guild)]
|
||||||
// public async Task Leave(IUserMessage umsg, [Remainder] string guildStr)
|
// public async Task Leave(IUserMessage umsg, [Remainder] string guildStr)
|
||||||
// {
|
// {
|
||||||
|
@ -106,7 +106,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[RequirePermission(GuildPermission.ManageGuild)]
|
[RequirePermission(GuildPermission.ManageGuild)]
|
||||||
public async Task GreetDel(IUserMessage umsg)
|
public async Task GreetDel(IUserMessage umsg)
|
||||||
@ -128,7 +128,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
await channel.SendMessageAsync("`Automatic deletion of greet messages has been disabled.`").ConfigureAwait(false);
|
await channel.SendMessageAsync("`Automatic deletion of greet messages has been disabled.`").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[RequirePermission(GuildPermission.ManageGuild)]
|
[RequirePermission(GuildPermission.ManageGuild)]
|
||||||
public async Task Greet(IUserMessage umsg)
|
public async Task Greet(IUserMessage umsg)
|
||||||
@ -151,7 +151,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
await channel.SendMessageAsync("Greet announcements disabled.").ConfigureAwait(false);
|
await channel.SendMessageAsync("Greet announcements disabled.").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[RequirePermission(GuildPermission.ManageGuild)]
|
[RequirePermission(GuildPermission.ManageGuild)]
|
||||||
public async Task GreetMsg(IUserMessage umsg, [Remainder] string text)
|
public async Task GreetMsg(IUserMessage umsg, [Remainder] string text)
|
||||||
@ -180,7 +180,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
await channel.SendMessageAsync("Enable greet messsages by typing `.greet`").ConfigureAwait(false);
|
await channel.SendMessageAsync("Enable greet messsages by typing `.greet`").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[RequirePermission(GuildPermission.ManageGuild)]
|
[RequirePermission(GuildPermission.ManageGuild)]
|
||||||
public async Task GreetDm(IUserMessage umsg)
|
public async Task GreetDm(IUserMessage umsg)
|
||||||
@ -202,7 +202,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
await channel.SendMessageAsync("Greet announcements disabled.").ConfigureAwait(false);
|
await channel.SendMessageAsync("Greet announcements disabled.").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[RequirePermission(GuildPermission.ManageGuild)]
|
[RequirePermission(GuildPermission.ManageGuild)]
|
||||||
public async Task GreetDmMsg(IUserMessage umsg, [Remainder] string text)
|
public async Task GreetDmMsg(IUserMessage umsg, [Remainder] string text)
|
||||||
@ -231,7 +231,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
await channel.SendMessageAsync("Enable DM greet messsages by typing `.greetdm`").ConfigureAwait(false);
|
await channel.SendMessageAsync("Enable DM greet messsages by typing `.greetdm`").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[RequirePermission(GuildPermission.ManageGuild)]
|
[RequirePermission(GuildPermission.ManageGuild)]
|
||||||
public async Task Bye(IUserMessage umsg)
|
public async Task Bye(IUserMessage umsg)
|
||||||
@ -254,7 +254,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
await channel.SendMessageAsync("Bye announcements disabled.").ConfigureAwait(false);
|
await channel.SendMessageAsync("Bye announcements disabled.").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[RequirePermission(GuildPermission.ManageGuild)]
|
[RequirePermission(GuildPermission.ManageGuild)]
|
||||||
public async Task ByeMsg(IUserMessage umsg, [Remainder] string text)
|
public async Task ByeMsg(IUserMessage umsg, [Remainder] string text)
|
||||||
@ -283,7 +283,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
await channel.SendMessageAsync("Enable bye messsages by typing `.bye`").ConfigureAwait(false);
|
await channel.SendMessageAsync("Enable bye messsages by typing `.bye`").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[RequirePermission(GuildPermission.ManageGuild)]
|
[RequirePermission(GuildPermission.ManageGuild)]
|
||||||
public async Task ByeDel(IUserMessage umsg)
|
public async Task ByeDel(IUserMessage umsg)
|
||||||
|
@ -1,166 +0,0 @@
|
|||||||
//using Discord;
|
|
||||||
//using Discord.Commands;
|
|
||||||
//using NadekoBot.Classes;
|
|
||||||
//using NadekoBot.Extensions;
|
|
||||||
//using NadekoBot.Modules.Permissions.Classes;
|
|
||||||
//using System;
|
|
||||||
//using System.Linq;
|
|
||||||
//using System.Text.RegularExpressions;
|
|
||||||
//using System.Threading.Tasks;
|
|
||||||
//using ChPermOverride = Discord.ChannelPermissionOverrides;
|
|
||||||
|
|
||||||
////todo DB
|
|
||||||
////todo rewrite
|
|
||||||
//namespace NadekoBot.Modules.Administration
|
|
||||||
//{
|
|
||||||
// internal class VoicePlusTextCommand : DiscordCommand
|
|
||||||
// {
|
|
||||||
// Regex channelNameRegex = new Regex(@"[^a-zA-Z0-9 -]", RegexOptions.Compiled);
|
|
||||||
// public VoicePlusTextCommand(DiscordModule module) : base(module)
|
|
||||||
// {
|
|
||||||
// // changing servers may cause bugs
|
|
||||||
// NadekoBot.Client.UserUpdated += async (sender, e) =>
|
|
||||||
// {
|
|
||||||
// try
|
|
||||||
// {
|
|
||||||
// if (e.Server == null)
|
|
||||||
// return;
|
|
||||||
// var config = SpecificConfigurations.Default.Of(e.Server.Id);
|
|
||||||
// if (e.Before.VoiceChannel == e.After.VoiceChannel) return;
|
|
||||||
// if (!config.VoicePlusTextEnabled)
|
|
||||||
// return;
|
|
||||||
// var serverPerms = e.Server.GetUser(NadekoBot.Client.CurrentUser.Id)?.ServerPermissions;
|
|
||||||
// if (serverPerms == null)
|
|
||||||
// return;
|
|
||||||
// if (!serverPerms.Value.ManageChannels || !serverPerms.Value.ManageRoles)
|
|
||||||
// {
|
|
||||||
|
|
||||||
// try
|
|
||||||
// {
|
|
||||||
// await e.Server.Owner.SendMessageAsync(
|
|
||||||
// "I don't have manage server and/or Manage Channels permission," +
|
|
||||||
// $" so I cannot run voice+text on **{e.Server.Name}** server.").ConfigureAwait(false);
|
|
||||||
// }
|
|
||||||
// catch { } // meh
|
|
||||||
// config.VoicePlusTextEnabled = false;
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
// var beforeVch = e.Before.VoiceChannel;
|
|
||||||
// if (beforeVch != null)
|
|
||||||
// {
|
|
||||||
// var textChannel =
|
|
||||||
// e.Server.FindChannels(GetChannelName(beforeVch.Name), ChannelType.Text).FirstOrDefault();
|
|
||||||
// if (textChannel != null)
|
|
||||||
// await textChannel.AddPermissionsRule(e.Before,
|
|
||||||
// new ChPermOverride(readMessages: PermValue.Deny,
|
|
||||||
// sendMessages: PermValue.Deny)).ConfigureAwait(false);
|
|
||||||
// }
|
|
||||||
// var afterVch = e.After.VoiceChannel;
|
|
||||||
// if (afterVch != null && e.Server.AFKChannel != afterVch)
|
|
||||||
// {
|
|
||||||
// var textChannel = e.Server.FindChannels(
|
|
||||||
// GetChannelName(afterVch.Name),
|
|
||||||
// ChannelType.Text)
|
|
||||||
// .FirstOrDefault();
|
|
||||||
// if (textChannel == null)
|
|
||||||
// {
|
|
||||||
// textChannel = (await e.Server.CreateChannel(GetChannelName(afterVch.Name), ChannelType.Text).ConfigureAwait(false));
|
|
||||||
// await textChannel.AddPermissionsRule(e.Server.EveryoneRole,
|
|
||||||
// new ChPermOverride(readMessages: PermValue.Deny,
|
|
||||||
// sendMessages: PermValue.Deny)).ConfigureAwait(false);
|
|
||||||
// }
|
|
||||||
// await textChannel.AddPermissionsRule(e.After,
|
|
||||||
// new ChPermOverride(readMessages: PermValue.Allow,
|
|
||||||
// sendMessages: PermValue.Allow)).ConfigureAwait(false);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// catch (Exception ex)
|
|
||||||
// {
|
|
||||||
// Console.WriteLine(ex);
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|
||||||
// private string GetChannelName(string voiceName) =>
|
|
||||||
// channelNameRegex.Replace(voiceName, "").Trim().Replace(" ", "-").TrimTo(90, true) + "-voice";
|
|
||||||
|
|
||||||
// internal override void Init(CommandGroupBuilder cgb)
|
|
||||||
// {
|
|
||||||
// cgb.CreateCommand(Module.Prefix + "cleanv+t")
|
|
||||||
// .Alias(Module.Prefix + "cv+t")
|
|
||||||
// .Description($"Deletes all text channels ending in `-voice` for which voicechannels are not found. **Use at your own risk.\nNeeds Manage Roles and Manage Channels Permissions.** | `{Prefix}cleanv+t`")
|
|
||||||
// .AddCheck(SimpleCheckers.CanManageRoles)
|
|
||||||
// .AddCheck(SimpleCheckers.ManageChannels())
|
|
||||||
// .Do(async e =>
|
|
||||||
// {
|
|
||||||
// if (!e.Server.CurrentUser.ServerPermissions.ManageChannels)
|
|
||||||
// {
|
|
||||||
// await channel.SendMessageAsync("`I have insufficient permission to do that.`");
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// var allTxtChannels = e.Server.TextChannels.Where(c => c.Name.EndsWith("-voice"));
|
|
||||||
// var validTxtChannelNames = e.Server.VoiceChannels.Select(c => GetChannelName(c.Name));
|
|
||||||
|
|
||||||
// var invalidTxtChannels = allTxtChannels.Where(c => !validTxtChannelNames.Contains(c.Name));
|
|
||||||
|
|
||||||
// foreach (var c in invalidTxtChannels)
|
|
||||||
// {
|
|
||||||
// try
|
|
||||||
// {
|
|
||||||
// await c.Delete();
|
|
||||||
// }
|
|
||||||
// catch { }
|
|
||||||
// await Task.Delay(500);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// await channel.SendMessageAsync("`Done.`");
|
|
||||||
// });
|
|
||||||
|
|
||||||
// cgb.CreateCommand(Module.Prefix + "voice+text")
|
|
||||||
// .Alias(Module.Prefix + "v+t")
|
|
||||||
// .Description("Creates a text channel for each voice channel only users in that voice channel can see." +
|
|
||||||
// $"If you are server owner, keep in mind you will see them all the time regardless. **Needs Manage Roles and Manage Channels Permissions.**| `{Prefix}voice+text`")
|
|
||||||
// .AddCheck(SimpleCheckers.ManageChannels())
|
|
||||||
// .AddCheck(SimpleCheckers.CanManageRoles)
|
|
||||||
// .Do(async e =>
|
|
||||||
// {
|
|
||||||
// try
|
|
||||||
// {
|
|
||||||
// var config = SpecificConfigurations.Default.Of(e.Server.Id);
|
|
||||||
// if (config.VoicePlusTextEnabled == true)
|
|
||||||
// {
|
|
||||||
// config.VoicePlusTextEnabled = false;
|
|
||||||
// foreach (var textChannel in e.Server.TextChannels.Where(c => c.Name.EndsWith("-voice")))
|
|
||||||
// {
|
|
||||||
// try
|
|
||||||
// {
|
|
||||||
// await textChannel.Delete().ConfigureAwait(false);
|
|
||||||
// }
|
|
||||||
// catch
|
|
||||||
// {
|
|
||||||
// await channel.SendMessageAsync(
|
|
||||||
// ":anger: Error: Most likely i don't have permissions to do this.")
|
|
||||||
// .ConfigureAwait(false);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// await channel.SendMessageAsync("Successfuly removed voice + text feature.").ConfigureAwait(false);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// config.VoicePlusTextEnabled = true;
|
|
||||||
// await channel.SendMessageAsync("Successfuly enabled voice + text feature. " +
|
|
||||||
// "**Make sure the bot has manage roles and manage channels permissions**")
|
|
||||||
// .ConfigureAwait(false);
|
|
||||||
|
|
||||||
// }
|
|
||||||
// catch (Exception ex)
|
|
||||||
// {
|
|
||||||
// await channel.SendMessageAsync(ex.ToString()).ConfigureAwait(false);
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//}
|
|
@ -0,0 +1,170 @@
|
|||||||
|
using Discord;
|
||||||
|
using Discord.Commands;
|
||||||
|
using Discord.WebSocket;
|
||||||
|
using NadekoBot.Attributes;
|
||||||
|
using NadekoBot.Extensions;
|
||||||
|
using NadekoBot.Services;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NadekoBot.Modules.Administration
|
||||||
|
{
|
||||||
|
public partial class Administration
|
||||||
|
{
|
||||||
|
[Group]
|
||||||
|
public class VoicePlusTextCommands
|
||||||
|
{
|
||||||
|
Regex channelNameRegex = new Regex(@"[^a-zA-Z0-9 -]", RegexOptions.Compiled);
|
||||||
|
//guildid/voiceplustextenabled
|
||||||
|
private ConcurrentDictionary<ulong, bool> voicePlusTextCache;
|
||||||
|
public VoicePlusTextCommands()
|
||||||
|
{
|
||||||
|
NadekoBot.Client.UserUpdated += UserUpdatedEventHandler;
|
||||||
|
voicePlusTextCache = new ConcurrentDictionary<ulong, bool>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Task UserUpdatedEventHandler(IGuildUser before, IGuildUser after)
|
||||||
|
{
|
||||||
|
var task = Task.Run(async () =>
|
||||||
|
{
|
||||||
|
var guild = before.Guild ?? after.Guild;
|
||||||
|
var botUserPerms = guild.GetCurrentUser().GuildPermissions;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (before.VoiceChannel == after.VoiceChannel) return;
|
||||||
|
|
||||||
|
bool isEnabled;
|
||||||
|
voicePlusTextCache.TryGetValue(guild.Id, out isEnabled);
|
||||||
|
if (!isEnabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!botUserPerms.ManageChannels || !botUserPerms.ManageRoles)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await (await guild.GetOwnerAsync()).SendMessageAsync(
|
||||||
|
"I don't have manage server and/or Manage Channels permission," +
|
||||||
|
$" so I cannot run voice+text on **{guild.Name}** server.").ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
|
{
|
||||||
|
uow.GuildConfigs.For(before.Guild.Id).VoicePlusTextEnabled = false;
|
||||||
|
voicePlusTextCache.TryUpdate(guild.Id, false, true);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var beforeVch = before.VoiceChannel;
|
||||||
|
if (beforeVch != null)
|
||||||
|
{
|
||||||
|
var textChannel = guild.GetTextChannels().Where(t => t.Name == GetChannelName(beforeVch.Name)).FirstOrDefault();
|
||||||
|
if (textChannel != null)
|
||||||
|
await textChannel.AddPermissionOverwriteAsync(before,
|
||||||
|
new OverwritePermissions(readMessages: PermValue.Deny,
|
||||||
|
sendMessages: PermValue.Deny)).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
var afterVch = after.VoiceChannel;
|
||||||
|
if (afterVch != null && guild.AFKChannelId != afterVch.Id)
|
||||||
|
{
|
||||||
|
var textChannel = guild.GetTextChannels()
|
||||||
|
.Where(t => t.Name == GetChannelName(afterVch.Name))
|
||||||
|
.FirstOrDefault();
|
||||||
|
if (textChannel == null)
|
||||||
|
{
|
||||||
|
textChannel = (await guild.CreateTextChannelAsync(GetChannelName(afterVch.Name)).ConfigureAwait(false));
|
||||||
|
await textChannel.AddPermissionOverwriteAsync(guild.EveryoneRole,
|
||||||
|
new OverwritePermissions(readMessages: PermValue.Deny,
|
||||||
|
sendMessages: PermValue.Deny)).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
await textChannel.AddPermissionOverwriteAsync(after,
|
||||||
|
new OverwritePermissions(readMessages: PermValue.Allow,
|
||||||
|
sendMessages: PermValue.Allow)).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine(ex);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetChannelName(string voiceName) =>
|
||||||
|
channelNameRegex.Replace(voiceName, "").Trim().Replace(" ", "-").TrimTo(90, true) + "-voice";
|
||||||
|
|
||||||
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
|
[RequireContext(ContextType.Guild)]
|
||||||
|
[RequirePermission(GuildPermission.ManageRoles)]
|
||||||
|
[RequirePermission(GuildPermission.ManageChannels)]
|
||||||
|
public async Task VoicePlusText(IUserMessage msg, [Remainder] string arg)
|
||||||
|
{
|
||||||
|
var channel = (ITextChannel)msg.Channel;
|
||||||
|
var guild = channel.Guild;
|
||||||
|
|
||||||
|
var botUser = guild.GetCurrentUser();
|
||||||
|
if (!botUser.GuildPermissions.ManageRoles || !botUser.GuildPermissions.ManageChannels)
|
||||||
|
{
|
||||||
|
await channel.SendMessageAsync(":anger: `I require manage roles and manage channels permissions to enable this feature.`");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
bool isEnabled;
|
||||||
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
|
{
|
||||||
|
var conf = uow.GuildConfigs.For(guild.Id);
|
||||||
|
isEnabled = conf.VoicePlusTextEnabled = !conf.VoicePlusTextEnabled;
|
||||||
|
}
|
||||||
|
voicePlusTextCache.AddOrUpdate(guild.Id, isEnabled, (id, val) => isEnabled);
|
||||||
|
if (isEnabled)
|
||||||
|
{
|
||||||
|
foreach (var textChannel in guild.GetTextChannels().Where(c => c.Name.EndsWith("-voice")))
|
||||||
|
{
|
||||||
|
try { await textChannel.DeleteAsync().ConfigureAwait(false); } catch { }
|
||||||
|
}
|
||||||
|
await channel.SendMessageAsync("Successfuly removed voice + text feature.").ConfigureAwait(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await channel.SendMessageAsync("Successfuly enabled voice + text feature.").ConfigureAwait(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
await channel.SendMessageAsync(ex.ToString()).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
|
[RequireContext(ContextType.Guild)]
|
||||||
|
[RequirePermission(GuildPermission.ManageChannels)]
|
||||||
|
[RequirePermission(GuildPermission.ManageRoles)]
|
||||||
|
public async Task CleanVPlusT(IUserMessage msg, [Remainder] string arg)
|
||||||
|
{
|
||||||
|
var channel = (ITextChannel)msg.Channel;
|
||||||
|
var guild = channel.Guild;
|
||||||
|
if (!guild.GetCurrentUser().GuildPermissions.ManageChannels)
|
||||||
|
{
|
||||||
|
await channel.SendMessageAsync("`I have insufficient permission to do that.`");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var allTxtChannels = guild.GetTextChannels().Where(c => c.Name.EndsWith("-voice"));
|
||||||
|
var validTxtChannelNames = guild.GetVoiceChannels().Select(c => GetChannelName(c.Name));
|
||||||
|
|
||||||
|
var invalidTxtChannels = allTxtChannels.Where(c => !validTxtChannelNames.Contains(c.Name));
|
||||||
|
|
||||||
|
foreach (var c in invalidTxtChannels)
|
||||||
|
{
|
||||||
|
try { await c.DeleteAsync().ConfigureAwait(false); } catch { }
|
||||||
|
await Task.Delay(500);
|
||||||
|
}
|
||||||
|
|
||||||
|
await channel.SendMessageAsync("`Done.`");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -12,10 +12,9 @@ using NadekoBot.Services.Database.Models;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NadekoBot.Services.Database;
|
using NadekoBot.Services.Database;
|
||||||
|
|
||||||
//todo DB
|
|
||||||
namespace NadekoBot.Modules.ClashOfClans
|
namespace NadekoBot.Modules.ClashOfClans
|
||||||
{
|
{
|
||||||
[Module(",", AppendSpace = false)]
|
[NadekoModule("ClashOfClans", ",")]
|
||||||
public class ClashOfClans : DiscordModule
|
public class ClashOfClans : DiscordModule
|
||||||
{
|
{
|
||||||
public static ConcurrentDictionary<ulong, List<ClashWar>> ClashWars { get; set; } = new ConcurrentDictionary<ulong, List<ClashWar>>();
|
public static ConcurrentDictionary<ulong, List<ClashWar>> ClashWars { get; set; } = new ConcurrentDictionary<ulong, List<ClashWar>>();
|
||||||
@ -55,7 +54,7 @@ namespace NadekoBot.Modules.ClashOfClans
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task CreateWar(IUserMessage umsg, int size, [Remainder] string enemyClan = null)
|
public async Task CreateWar(IUserMessage umsg, int size, [Remainder] string enemyClan = null)
|
||||||
{
|
{
|
||||||
@ -88,7 +87,7 @@ namespace NadekoBot.Modules.ClashOfClans
|
|||||||
await channel.SendMessageAsync($"❗🔰**CREATED CLAN WAR AGAINST {cw.ShortPrint()}**").ConfigureAwait(false);
|
await channel.SendMessageAsync($"❗🔰**CREATED CLAN WAR AGAINST {cw.ShortPrint()}**").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task StartWar(IUserMessage umsg, [Remainder] string number = null)
|
public async Task StartWar(IUserMessage umsg, [Remainder] string number = null)
|
||||||
{
|
{
|
||||||
@ -116,7 +115,7 @@ namespace NadekoBot.Modules.ClashOfClans
|
|||||||
SaveWar(war);
|
SaveWar(war);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task ListWar(IUserMessage umsg, [Remainder] string number = null)
|
public async Task ListWar(IUserMessage umsg, [Remainder] string number = null)
|
||||||
{
|
{
|
||||||
@ -159,7 +158,7 @@ namespace NadekoBot.Modules.ClashOfClans
|
|||||||
await channel.SendMessageAsync(warsInfo.Item1[warsInfo.Item2].ToPrettyString()).ConfigureAwait(false);
|
await channel.SendMessageAsync(warsInfo.Item1[warsInfo.Item2].ToPrettyString()).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Claim(IUserMessage umsg, int number, int baseNumber, [Remainder] string other_name = null)
|
public async Task Claim(IUserMessage umsg, int number, int baseNumber, [Remainder] string other_name = null)
|
||||||
{
|
{
|
||||||
@ -187,7 +186,7 @@ namespace NadekoBot.Modules.ClashOfClans
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task ClaimFinish1(IUserMessage umsg, int number, int baseNumber, [Remainder] string other_name = null)
|
public async Task ClaimFinish1(IUserMessage umsg, int number, int baseNumber, [Remainder] string other_name = null)
|
||||||
{
|
{
|
||||||
@ -195,7 +194,7 @@ namespace NadekoBot.Modules.ClashOfClans
|
|||||||
await FinishClaim(umsg, number, baseNumber, other_name, 1);
|
await FinishClaim(umsg, number, baseNumber, other_name, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task ClaimFinish2(IUserMessage umsg, int number, int baseNumber, [Remainder] string other_name = null)
|
public async Task ClaimFinish2(IUserMessage umsg, int number, int baseNumber, [Remainder] string other_name = null)
|
||||||
{
|
{
|
||||||
@ -203,7 +202,7 @@ namespace NadekoBot.Modules.ClashOfClans
|
|||||||
await FinishClaim(umsg, number, baseNumber, other_name, 2);
|
await FinishClaim(umsg, number, baseNumber, other_name, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task ClaimFinish(IUserMessage umsg, int number, int baseNumber, [Remainder] string other_name = null)
|
public async Task ClaimFinish(IUserMessage umsg, int number, int baseNumber, [Remainder] string other_name = null)
|
||||||
{
|
{
|
||||||
@ -211,7 +210,7 @@ namespace NadekoBot.Modules.ClashOfClans
|
|||||||
await FinishClaim(umsg, number, baseNumber, other_name);
|
await FinishClaim(umsg, number, baseNumber, other_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task EndWar(IUserMessage umsg, int number)
|
public async Task EndWar(IUserMessage umsg, int number)
|
||||||
{
|
{
|
||||||
@ -232,7 +231,7 @@ namespace NadekoBot.Modules.ClashOfClans
|
|||||||
warsInfo.Item1.RemoveAt(warsInfo.Item2);
|
warsInfo.Item1.RemoveAt(warsInfo.Item2);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Unclaim(IUserMessage umsg, int number, [Remainder] string otherName = null)
|
public async Task Unclaim(IUserMessage umsg, int number, [Remainder] string otherName = null)
|
||||||
{
|
{
|
||||||
|
@ -8,10 +8,10 @@ namespace NadekoBot.Modules
|
|||||||
{
|
{
|
||||||
public class DiscordModule
|
public class DiscordModule
|
||||||
{
|
{
|
||||||
protected ILocalization _l;
|
protected ILocalization _l { get; }
|
||||||
protected CommandService _commands;
|
protected CommandService _commands { get; }
|
||||||
protected DiscordSocketClient _client;
|
protected DiscordSocketClient _client { get; }
|
||||||
protected Logger _log;
|
protected Logger _log { get; }
|
||||||
|
|
||||||
public DiscordModule(ILocalization loc, CommandService cmds, DiscordSocketClient client)
|
public DiscordModule(ILocalization loc, CommandService cmds, DiscordSocketClient client)
|
||||||
{
|
{
|
||||||
|
@ -20,7 +20,7 @@ namespace NadekoBot.Modules.Gambling
|
|||||||
{
|
{
|
||||||
public static ConcurrentDictionary<ulong, AnimalRace> AnimalRaces = new ConcurrentDictionary<ulong, AnimalRace>();
|
public static ConcurrentDictionary<ulong, AnimalRace> AnimalRaces = new ConcurrentDictionary<ulong, AnimalRace>();
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Race(IUserMessage umsg)
|
public async Task Race(IUserMessage umsg)
|
||||||
{
|
{
|
||||||
@ -32,7 +32,7 @@ namespace NadekoBot.Modules.Gambling
|
|||||||
await channel.SendMessageAsync("🏁 `Failed starting a race. Another race is probably running.`");
|
await channel.SendMessageAsync("🏁 `Failed starting a race. Another race is probably running.`");
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task JoinRace(IUserMessage umsg, int amount = 0)
|
public async Task JoinRace(IUserMessage umsg, int amount = 0)
|
||||||
{
|
{
|
||||||
@ -41,17 +41,10 @@ namespace NadekoBot.Modules.Gambling
|
|||||||
if (amount < 0)
|
if (amount < 0)
|
||||||
amount = 0;
|
amount = 0;
|
||||||
|
|
||||||
//todo DB
|
if (amount > 0)
|
||||||
//var userFlowers = Gambling.GetUserFlowers(umsg.Author.Id);
|
if(!await CurrencyHandler.RemoveCurrencyAsync((IGuildUser)umsg.Author, "BetRace", amount, true).ConfigureAwait(false))
|
||||||
|
await channel.SendMessageAsync($"{umsg.Author.Mention} You don't have enough {Gambling.CurrencyName}s.").ConfigureAwait(false);
|
||||||
|
|
||||||
//if (userFlowers < amount)
|
|
||||||
//{
|
|
||||||
// await channel.SendMessageAsync($"{umsg.Author.Mention} You don't have enough {NadekoBot.Config.CurrencyName}s. You only have {userFlowers}{NadekoBot.Config.CurrencySign}.").ConfigureAwait(false);
|
|
||||||
// return;
|
|
||||||
//}
|
|
||||||
|
|
||||||
//if (amount > 0)
|
|
||||||
// await FlowersHandler.RemoveFlowers(umsg.Author, "BetRace", (int)amount, true).ConfigureAwait(false);
|
|
||||||
|
|
||||||
AnimalRace ar;
|
AnimalRace ar;
|
||||||
if (!AnimalRaces.TryGetValue(channel.Guild.Id, out ar))
|
if (!AnimalRaces.TryGetValue(channel.Guild.Id, out ar))
|
||||||
@ -67,7 +60,7 @@ namespace NadekoBot.Modules.Gambling
|
|||||||
|
|
||||||
private ConcurrentQueue<string> animals { get; }
|
private ConcurrentQueue<string> animals { get; }
|
||||||
|
|
||||||
public bool Fail { get; internal set; }
|
public bool Fail { get; set; }
|
||||||
|
|
||||||
public List<Participant> participants = new List<Participant>();
|
public List<Participant> participants = new List<Participant>();
|
||||||
private ulong serverId;
|
private ulong serverId;
|
||||||
@ -116,9 +109,9 @@ namespace NadekoBot.Modules.Gambling
|
|||||||
{
|
{
|
||||||
await raceChannel.SendMessageAsync("🏁`Race failed to start since there was not enough participants.`");
|
await raceChannel.SendMessageAsync("🏁`Race failed to start since there was not enough participants.`");
|
||||||
var p = participants.FirstOrDefault();
|
var p = participants.FirstOrDefault();
|
||||||
//todo DB
|
|
||||||
//if (p != null)
|
if (p != null)
|
||||||
// await FlowersHandler.AddFlowersAsync(p.User, "BetRace", p.AmountBet, true).ConfigureAwait(false);
|
await CurrencyHandler.AddCurrencyAsync(p.User, "BetRace", p.AmountBet, true).ConfigureAwait(false);
|
||||||
End();
|
End();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -137,7 +130,7 @@ namespace NadekoBot.Modules.Gambling
|
|||||||
|
|
||||||
private async Task StartRace()
|
private async Task StartRace()
|
||||||
{
|
{
|
||||||
var rng = new Random();
|
var rng = new NadekoRandom();
|
||||||
Participant winner = null;
|
Participant winner = null;
|
||||||
IUserMessage msg = null;
|
IUserMessage msg = null;
|
||||||
int place = 1;
|
int place = 1;
|
||||||
@ -150,7 +143,6 @@ namespace NadekoBot.Modules.Gambling
|
|||||||
//update the state
|
//update the state
|
||||||
participants.ForEach(p =>
|
participants.ForEach(p =>
|
||||||
{
|
{
|
||||||
|
|
||||||
p.Total += 1 + rng.Next(0, 10);
|
p.Total += 1 + rng.Next(0, 10);
|
||||||
if (p.Total > 60)
|
if (p.Total > 60)
|
||||||
{
|
{
|
||||||
@ -191,8 +183,8 @@ namespace NadekoBot.Modules.Gambling
|
|||||||
if (winner.AmountBet > 0)
|
if (winner.AmountBet > 0)
|
||||||
{
|
{
|
||||||
var wonAmount = winner.AmountBet * (participants.Count - 1);
|
var wonAmount = winner.AmountBet * (participants.Count - 1);
|
||||||
//todo DB
|
|
||||||
//await FlowersHandler.AddFlowersAsync(winner.User, "Won a Race", wonAmount).ConfigureAwait(false);
|
await CurrencyHandler.AddCurrencyAsync(winner.User, "Won a Race", wonAmount, false).ConfigureAwait(false);
|
||||||
await raceChannel.SendMessageAsync($"🏁 {winner.User.Mention} as {winner.Animal} **Won the race and {wonAmount}{CurrencySign}!**").ConfigureAwait(false);
|
await raceChannel.SendMessageAsync($"🏁 {winner.User.Mention} as {winner.Animal} **Won the race and {wonAmount}{CurrencySign}!**").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -202,14 +194,15 @@ namespace NadekoBot.Modules.Gambling
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task Client_MessageReceived(IMessage imsg)
|
private Task Client_MessageReceived(IMessage imsg)
|
||||||
{
|
{
|
||||||
var msg = imsg as IUserMessage;
|
var msg = imsg as IUserMessage;
|
||||||
if (msg == null)
|
if (msg == null)
|
||||||
return;
|
return Task.CompletedTask;
|
||||||
if (await msg.IsAuthor() || !(imsg.Channel is ITextChannel) || imsg.Channel != raceChannel)
|
if (msg.IsAuthor() || !(imsg.Channel is ITextChannel) || imsg.Channel != raceChannel)
|
||||||
return;
|
return Task.CompletedTask;
|
||||||
messagesSinceGameStarted++;
|
messagesSinceGameStarted++;
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task CheckForFullGameAsync(CancellationToken cancelToken)
|
private async Task CheckForFullGameAsync(CancellationToken cancelToken)
|
||||||
|
@ -2,6 +2,7 @@ using Discord;
|
|||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using NadekoBot.Attributes;
|
using NadekoBot.Attributes;
|
||||||
using NadekoBot.Extensions;
|
using NadekoBot.Extensions;
|
||||||
|
using NadekoBot.Services;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -13,20 +14,21 @@ namespace NadekoBot.Modules.Gambling
|
|||||||
public partial class Gambling
|
public partial class Gambling
|
||||||
{
|
{
|
||||||
private Regex dndRegex { get; } = new Regex(@"(?<n1>\d+)d(?<n2>\d+)", RegexOptions.Compiled);
|
private Regex dndRegex { get; } = new Regex(@"(?<n1>\d+)d(?<n2>\d+)", RegexOptions.Compiled);
|
||||||
////todo drawing
|
|
||||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
|
||||||
//[RequireContext(ContextType.Guild)]
|
|
||||||
//public Task Roll(IUserMessage umsg, [Remainder] string arg = null) =>
|
|
||||||
// InternalRoll(umsg, arg, true);
|
|
||||||
|
|
||||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
//[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
//public Task Rolluo(IUserMessage umsg, [Remainder] string arg = null) =>
|
public Task Roll(IUserMessage umsg, [Remainder] string arg = null) =>
|
||||||
// InternalRoll(umsg, arg, false);
|
publicRoll(umsg, arg, true);
|
||||||
|
|
||||||
//private async Task InternalRoll(IUserMessage umsg, string arg, bool ordered) {
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
// var channel = (ITextChannel)umsg.Channel;
|
[RequireContext(ContextType.Guild)]
|
||||||
// var r = new Random();
|
public Task Rolluo(IUserMessage umsg, [Remainder] string arg = null) =>
|
||||||
|
publicRoll(umsg, arg, false);
|
||||||
|
//todo drawing
|
||||||
|
private async Task publicRoll(IUserMessage umsg, string arg, bool ordered)
|
||||||
|
{
|
||||||
|
var channel = (ITextChannel)umsg.Channel;
|
||||||
|
var r = new NadekoRandom();
|
||||||
//if (string.IsNullOrWhiteSpace(arg))
|
//if (string.IsNullOrWhiteSpace(arg))
|
||||||
//{
|
//{
|
||||||
// var gen = r.Next(0, 101);
|
// var gen = r.Next(0, 101);
|
||||||
@ -39,25 +41,25 @@ namespace NadekoBot.Modules.Gambling
|
|||||||
// await channel.SendFileAsync(imageStream, "dice.png").ConfigureAwait(false);
|
// await channel.SendFileAsync(imageStream, "dice.png").ConfigureAwait(false);
|
||||||
// return;
|
// return;
|
||||||
//}
|
//}
|
||||||
// Match m;
|
Match m;
|
||||||
// if ((m = dndRegex.Match(arg)).Length != 0)
|
if ((m = dndRegex.Match(arg)).Length != 0)
|
||||||
// {
|
{
|
||||||
// int n1;
|
int n1;
|
||||||
// int n2;
|
int n2;
|
||||||
// if (int.TryParse(m.Groups["n1"].ToString(), out n1) &&
|
if (int.TryParse(m.Groups["n1"].ToString(), out n1) &&
|
||||||
// int.TryParse(m.Groups["n2"].ToString(), out n2) &&
|
int.TryParse(m.Groups["n2"].ToString(), out n2) &&
|
||||||
// n1 <= 50 && n2 <= 100000 && n1 > 0 && n2 > 0)
|
n1 <= 50 && n2 <= 100000 && n1 > 0 && n2 > 0)
|
||||||
// {
|
{
|
||||||
// var arr = new int[n1];
|
var arr = new int[n1];
|
||||||
// for (int i = 0; i < n1; i++)
|
for (int i = 0; i < n1; i++)
|
||||||
// {
|
{
|
||||||
// arr[i] = r.Next(1, n2 + 1);
|
arr[i] = r.Next(1, n2 + 1);
|
||||||
// }
|
}
|
||||||
// var elemCnt = 0;
|
var elemCnt = 0;
|
||||||
// await channel.SendMessageAsync($"`Rolled {n1} {(n1 == 1 ? "die" : "dice")} 1-{n2}.`\n`Result:` " + string.Join(", ", (ordered ? arr.OrderBy(x => x).AsEnumerable() : arr).Select(x => elemCnt++ % 2 == 0 ? $"**{x}**" : x.ToString()))).ConfigureAwait(false);
|
await channel.SendMessageAsync($"`Rolled {n1} {(n1 == 1 ? "die" : "dice")} 1-{n2}.`\n`Result:` " + string.Join(", ", (ordered ? arr.OrderBy(x => x).AsEnumerable() : arr).Select(x => elemCnt++ % 2 == 0 ? $"**{x}**" : x.ToString()))).ConfigureAwait(false);
|
||||||
// }
|
}
|
||||||
// return;
|
return;
|
||||||
// }
|
}
|
||||||
//try
|
//try
|
||||||
//{
|
//{
|
||||||
// var num = int.Parse(e.Args[0]);
|
// var num = int.Parse(e.Args[0]);
|
||||||
@ -103,9 +105,9 @@ namespace NadekoBot.Modules.Gambling
|
|||||||
//{
|
//{
|
||||||
// await channel.SendMessageAsync("Please enter a number of dice to roll.").ConfigureAwait(false);
|
// await channel.SendMessageAsync("Please enter a number of dice to roll.").ConfigureAwait(false);
|
||||||
//}
|
//}
|
||||||
//}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task NRoll(IUserMessage umsg, [Remainder] string range)
|
public async Task NRoll(IUserMessage umsg, [Remainder] string range)
|
||||||
{
|
{
|
||||||
@ -123,11 +125,11 @@ namespace NadekoBot.Modules.Gambling
|
|||||||
.ToArray();
|
.ToArray();
|
||||||
if (arr[0] > arr[1])
|
if (arr[0] > arr[1])
|
||||||
throw new ArgumentException("First argument should be bigger than the second one.");
|
throw new ArgumentException("First argument should be bigger than the second one.");
|
||||||
rolled = new Random().Next(arr[0], arr[1] + 1);
|
rolled = new NadekoRandom().Next(arr[0], arr[1] + 1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rolled = new Random().Next(0, int.Parse(range) + 1);
|
rolled = new NadekoRandom().Next(0, int.Parse(range) + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
await channel.SendMessageAsync($"{umsg.Author.Mention} rolled **{rolled}**.").ConfigureAwait(false);
|
await channel.SendMessageAsync($"{umsg.Author.Mention} rolled **{rolled}**.").ConfigureAwait(false);
|
||||||
|
@ -11,11 +11,11 @@
|
|||||||
////todo drawing
|
////todo drawing
|
||||||
//namespace NadekoBot.Modules.Gambling
|
//namespace NadekoBot.Modules.Gambling
|
||||||
//{
|
//{
|
||||||
// internal class DrawCommand : DiscordCommand
|
// public class DrawCommand : DiscordCommand
|
||||||
// {
|
// {
|
||||||
// public DrawCommand(DiscordModule module) : base(module) { }
|
// public DrawCommand(DiscordModule module) : base(module) { }
|
||||||
|
|
||||||
// internal override void Init(CommandGroupBuilder cgb)
|
// public override void Init(CommandGroupBuilder cgb)
|
||||||
// {
|
// {
|
||||||
// cgb.CreateCommand(Module.Prefix + "draw")
|
// cgb.CreateCommand(Module.Prefix + "draw")
|
||||||
// .Description($"Draws a card from the deck.If you supply number [x], she draws up to 5 cards from the deck. | `{Prefix}draw [x]`")
|
// .Description($"Draws a card from the deck.If you supply number [x], she draws up to 5 cards from the deck. | `{Prefix}draw [x]`")
|
||||||
|
@ -1,99 +1,30 @@
|
|||||||
//using Discord.Commands;
|
using Discord;
|
||||||
//using NadekoBot.Classes;
|
using Discord.Commands;
|
||||||
//using NadekoBot.Extensions;
|
|
||||||
//using System;
|
//todo drawing
|
||||||
//using System.Drawing;
|
namespace NadekoBot.Modules.Gambling
|
||||||
//using System.Threading.Tasks;
|
{
|
||||||
|
[Group]
|
||||||
|
public class FlipCoinCommands
|
||||||
|
{
|
||||||
|
|
||||||
|
public FlipCoinCommands() { }
|
||||||
|
|
||||||
|
|
||||||
////todo drawing
|
////todo drawing
|
||||||
//namespace NadekoBot.Modules.Gambling
|
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
|
//[RequireContext(ContextType.Guild)]
|
||||||
|
//public async Task Flip(IUserMessage imsg, int count = 0)
|
||||||
//{
|
//{
|
||||||
// internal class FlipCoinCommand : DiscordCommand
|
// var channel = (ITextChannel)imsg.Channel;
|
||||||
// {
|
// if (count == 0)
|
||||||
|
|
||||||
// public FlipCoinCommand(DiscordModule module) : base(module) { }
|
|
||||||
|
|
||||||
// internal override void Init(CommandGroupBuilder cgb)
|
|
||||||
// {
|
|
||||||
// cgb.CreateCommand(Module.Prefix + "flip")
|
|
||||||
// .Description($"Flips coin(s) - heads or tails, and shows an image. | `{Prefix}flip` or `{Prefix}flip 3`")
|
|
||||||
// .Parameter("count", ParameterType.Optional)
|
|
||||||
// .Do(FlipCoinFunc());
|
|
||||||
|
|
||||||
// cgb.CreateCommand(Module.Prefix + "betflip")
|
|
||||||
// .Alias(Prefix+"bf")
|
|
||||||
// .Description($"Bet to guess will the result be heads or tails. Guessing award you double flowers you've bet. | `{Prefix}bf 5 heads` or `{Prefix}bf 3 t`")
|
|
||||||
// .Parameter("amount", ParameterType.Required)
|
|
||||||
// .Parameter("guess", ParameterType.Required)
|
|
||||||
// .Do(BetFlipCoinFunc());
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// private readonly Random rng = new Random();
|
|
||||||
// public Func<CommandEventArgs, Task> BetFlipCoinFunc() => async e =>
|
|
||||||
// {
|
|
||||||
|
|
||||||
// var amountstr = amount.Trim();
|
|
||||||
|
|
||||||
// var guessStr = guess.Trim().ToUpperInvariant();
|
|
||||||
// if (guessStr != "H" && guessStr != "T" && guessStr != "HEADS" && guessStr != "TAILS")
|
|
||||||
// return;
|
|
||||||
|
|
||||||
// int amount;
|
|
||||||
// if (!int.TryParse(amountstr, out amount) || amount < 1)
|
|
||||||
// return;
|
|
||||||
|
|
||||||
// var userFlowers = Gambling.GetUserFlowers(umsg.Author.Id);
|
|
||||||
|
|
||||||
// if (userFlowers < amount)
|
|
||||||
// {
|
|
||||||
// await channel.SendMessageAsync($"{umsg.Author.Mention} You don't have enough {NadekoBot.Config.CurrencyName}s. You only have {userFlowers}{NadekoBot.Config.CurrencySign}.").ConfigureAwait(false);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// await FlowersHandler.RemoveFlowers(umsg.Author, "Betflip Gamble", (int)amount, true).ConfigureAwait(false);
|
|
||||||
// //heads = true
|
|
||||||
// //tails = false
|
|
||||||
|
|
||||||
// var guess = guessStr == "HEADS" || guessStr == "H";
|
|
||||||
// bool result = false;
|
|
||||||
// if (rng.Next(0, 2) == 1) {
|
|
||||||
// await e.Channel.SendFile("heads.png", Properties.Resources.heads.ToStream(System.Drawing.Imaging.ImageFormat.Png)).ConfigureAwait(false);
|
|
||||||
// result = true;
|
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
// await e.Channel.SendFile("tails.png", Properties.Resources.tails.ToStream(System.Drawing.Imaging.ImageFormat.Png)).ConfigureAwait(false);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// string str;
|
|
||||||
// if (guess == result)
|
|
||||||
// {
|
|
||||||
// str = $"{umsg.Author.Mention}`You guessed it!` You won {amount * 2}{NadekoBot.Config.CurrencySign}";
|
|
||||||
// await FlowersHandler.AddFlowersAsync(umsg.Author, "Betflip Gamble", amount * 2, true).ConfigureAwait(false);
|
|
||||||
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// str = $"{umsg.Author.Mention}`More luck next time.`";
|
|
||||||
|
|
||||||
// await channel.SendMessageAsync(str).ConfigureAwait(false);
|
|
||||||
// };
|
|
||||||
|
|
||||||
// public Func<CommandEventArgs, Task> FlipCoinFunc() => async e =>
|
|
||||||
// {
|
|
||||||
|
|
||||||
// if (count == "")
|
|
||||||
// {
|
// {
|
||||||
// if (rng.Next(0, 2) == 1)
|
// if (rng.Next(0, 2) == 1)
|
||||||
// await e.Channel.SendFile("heads.png", Properties.Resources.heads.ToStream(System.Drawing.Imaging.ImageFormat.Png)).ConfigureAwait(false);
|
// await channel.SendFileAsync("heads.png", ).ConfigureAwait(false);
|
||||||
// else
|
// else
|
||||||
// await e.Channel.SendFile("tails.png", Properties.Resources.tails.ToStream(System.Drawing.Imaging.ImageFormat.Png)).ConfigureAwait(false);
|
// await channel.SendFileAsync("tails.png", ).ConfigureAwait(false);
|
||||||
|
// return;
|
||||||
// }
|
// }
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// int result;
|
|
||||||
// if (int.TryParse(count, out result))
|
|
||||||
// {
|
|
||||||
// if (result > 10)
|
// if (result > 10)
|
||||||
// result = 10;
|
// result = 10;
|
||||||
// var imgs = new Image[result];
|
// var imgs = new Image[result];
|
||||||
@ -103,11 +34,60 @@
|
|||||||
// Properties.Resources.tails :
|
// Properties.Resources.tails :
|
||||||
// Properties.Resources.heads;
|
// Properties.Resources.heads;
|
||||||
// }
|
// }
|
||||||
// await e.Channel.SendFile($"{result} coins.png", imgs.Merge().ToStream(System.Drawing.Imaging.ImageFormat.Png)).ConfigureAwait(false);
|
// await channel.SendFile($"{result} coins.png", imgs.Merge().ToStream(System.Drawing.Imaging.ImageFormat.Png)).ConfigureAwait(false);
|
||||||
// return;
|
// return;
|
||||||
// }
|
|
||||||
// await channel.SendMessageAsync("Invalid number").ConfigureAwait(false);
|
// await channel.SendMessageAsync("Invalid number").ConfigureAwait(false);
|
||||||
//}
|
//}
|
||||||
// };
|
|
||||||
|
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
|
//[RequireContext(ContextType.Guild)]
|
||||||
|
//public async Task Betflip(IUserMessage umsg, int amount, string guess)
|
||||||
|
//{
|
||||||
|
// var channel = (ITextChannel)umsg.Channel;
|
||||||
|
// var guildUser = (IGuildUser)umsg.Author;
|
||||||
|
// var guessStr = guess.Trim().ToUpperInvariant();
|
||||||
|
// if (guessStr != "H" && guessStr != "T" && guessStr != "HEADS" && guessStr != "TAILS")
|
||||||
|
// return;
|
||||||
|
|
||||||
|
// if (amount < 1)
|
||||||
|
// return;
|
||||||
|
|
||||||
|
// var userFlowers = Gambling.GetUserFlowers(umsg.Author.Id);
|
||||||
|
|
||||||
|
// if (userFlowers < amount)
|
||||||
|
// {
|
||||||
|
// await channel.SendMessageAsync($"{umsg.Author.Mention} You don't have enough {Gambling.CurrencyName}s. You only have {userFlowers}{Gambling.CurrencySign}.").ConfigureAwait(false);
|
||||||
|
// return;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
// await CurrencyHandler.RemoveCurrencyAsync(guildUser, "Betflip Gamble", amount, false).ConfigureAwait(false);
|
||||||
|
// //heads = true
|
||||||
|
// //tails = false
|
||||||
|
|
||||||
|
// var isHeads = guessStr == "HEADS" || guessStr == "H";
|
||||||
|
// bool result = false;
|
||||||
|
// var rng = new NadekoRandom();
|
||||||
|
// if (rng.Next(0, 2) == 1)
|
||||||
|
// {
|
||||||
|
// await channel.SendFileAsync("heads.png", Properties.Resources.heads.ToStream(System.Drawing.Imaging.ImageFormat.Png)).ConfigureAwait(false);
|
||||||
|
// result = true;
|
||||||
// }
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// await channel.SendFileAsync("tails.png", Properties.Resources.tails.ToStream(System.Drawing.Imaging.ImageFormat.Png)).ConfigureAwait(false);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// string str;
|
||||||
|
// if (isHeads == result)
|
||||||
|
// {
|
||||||
|
// str = $"{umsg.Author.Mention}`You guessed it!` You won {amount * 2}{Gambling.CurrencySign}";
|
||||||
|
// await CurrencyHandler.AddCurrencyAsync((IGuildUser)umsg.Author, "Betflip Gamble", amount * 2, false).ConfigureAwait(false);
|
||||||
|
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// str = $"{umsg.Author.Mention}`More luck next time.`";
|
||||||
|
|
||||||
|
// await channel.SendMessageAsync(str).ConfigureAwait(false);
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
using System;
|
using NadekoBot.Extensions;
|
||||||
|
using NadekoBot.Services;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
@ -114,7 +116,7 @@ namespace NadekoBot.Modules.Gambling.Models
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private Random r = new Random();
|
private Random r = new NadekoRandom();
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Take a card from the pool, you either take it from the top if the deck is shuffled, or from a random place if the deck is in the default order.
|
/// Take a card from the pool, you either take it from the top if the deck is shuffled, or from a random place if the deck is in the default order.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -143,7 +145,7 @@ namespace NadekoBot.Modules.Gambling.Models
|
|||||||
private void Shuffle()
|
private void Shuffle()
|
||||||
{
|
{
|
||||||
if (cardPool.Count <= 1) return;
|
if (cardPool.Count <= 1) return;
|
||||||
var orderedPool = cardPool.OrderBy(x => r.Next());
|
var orderedPool = cardPool.Shuffle();
|
||||||
cardPool = cardPool as List<Card> ?? orderedPool.ToList();
|
cardPool = cardPool as List<Card> ?? orderedPool.ToList();
|
||||||
}
|
}
|
||||||
public override string ToString() => string.Concat(cardPool.Select(c => c.ToString())) + Environment.NewLine;
|
public override string ToString() => string.Concat(cardPool.Select(c => c.ToString())) + Environment.NewLine;
|
||||||
|
@ -9,11 +9,12 @@ using System.Threading.Tasks;
|
|||||||
using NadekoBot.Services;
|
using NadekoBot.Services;
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
using NadekoBot.Services.Database;
|
using NadekoBot.Services.Database;
|
||||||
|
using NadekoBot.Services.Database.Models;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
//todo DB
|
|
||||||
namespace NadekoBot.Modules.Gambling
|
namespace NadekoBot.Modules.Gambling
|
||||||
{
|
{
|
||||||
[Module("$", AppendSpace = false)]
|
[NadekoModule("Gambling", "$")]
|
||||||
public partial class Gambling : DiscordModule
|
public partial class Gambling : DiscordModule
|
||||||
{
|
{
|
||||||
public static string CurrencyName { get; set; }
|
public static string CurrencyName { get; set; }
|
||||||
@ -30,10 +31,9 @@ namespace NadekoBot.Modules.Gambling
|
|||||||
CurrencySign = conf.CurrencySign;
|
CurrencySign = conf.CurrencySign;
|
||||||
CurrencyPluralName = conf.CurrencyPluralName;
|
CurrencyPluralName = conf.CurrencyPluralName;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Raffle(IUserMessage umsg, [Remainder] IRole role = null)
|
public async Task Raffle(IUserMessage umsg, [Remainder] IRole role = null)
|
||||||
{
|
{
|
||||||
@ -43,55 +43,52 @@ namespace NadekoBot.Modules.Gambling
|
|||||||
|
|
||||||
var members = role.Members().Where(u => u.Status == UserStatus.Online);
|
var members = role.Members().Where(u => u.Status == UserStatus.Online);
|
||||||
var membersArray = members as IUser[] ?? members.ToArray();
|
var membersArray = members as IUser[] ?? members.ToArray();
|
||||||
var usr = membersArray[new Random().Next(0, membersArray.Length)];
|
var usr = membersArray[new NadekoRandom().Next(0, membersArray.Length)];
|
||||||
await channel.SendMessageAsync($"**Raffled user:** {usr.Username} (id: {usr.Id})").ConfigureAwait(false);
|
await channel.SendMessageAsync($"**Raffled user:** {usr.Username} (id: {usr.Id})").ConfigureAwait(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////todo DB
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
//[LocalizedCommand("$$$"), LocalizedDescription("$$$"), LocalizedSummary("$$$")]
|
[RequireContext(ContextType.Guild)]
|
||||||
//[RequireContext(ContextType.Guild)]
|
public async Task Cash(IUserMessage umsg, [Remainder] IUser user = null)
|
||||||
//public async Task Cash(IUserMessage umsg, [Remainder] string arg)
|
{
|
||||||
//{
|
var channel = (ITextChannel)umsg.Channel;
|
||||||
// var channel = (ITextChannel)umsg.Channel;
|
|
||||||
|
|
||||||
// var usr = e.Message.MentionedUsers.FirstOrDefault() ?? umsg.Author;
|
user = user ?? umsg.Author;
|
||||||
// var pts = GetUserFlowers(usr.Id);
|
long amount;
|
||||||
// var str = $"{usr.Name} has {pts} {NadekoBot.Config.CurrencySign}";
|
BotConfig config;
|
||||||
// await channel.SendMessageAsync(str).ConfigureAwait(false);
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
//}
|
{
|
||||||
|
amount = uow.Currency.GetUserCurrency(user.Id);
|
||||||
|
config = uow.BotConfig.GetOrCreate();
|
||||||
|
}
|
||||||
|
|
||||||
////todo DB
|
await channel.SendMessageAsync($"{user.Username} has {amount} {config.CurrencySign}").ConfigureAwait(false);
|
||||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
}
|
||||||
//[RequireContext(ContextType.Guild)]
|
|
||||||
//public async Task Give(IUserMessage umsg, long amount, [Remainder] IUser receiver)
|
|
||||||
//{
|
|
||||||
// var channel = (ITextChannel)umsg.Channel;
|
|
||||||
// if (amount <= 0)
|
|
||||||
// return;
|
|
||||||
// var userFlowers = GetUserFlowers(umsg.Author.Id);
|
|
||||||
|
|
||||||
// if (userFlowers < amount)
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
// {
|
[RequireContext(ContextType.Guild)]
|
||||||
// await channel.SendMessageAsync($"{umsg.Author.Mention} You don't have enough {NadekoBot.Config.CurrencyName}s. You only have {userFlowers}{NadekoBot.Config.CurrencySign}.").ConfigureAwait(false);
|
public async Task Give(IUserMessage umsg, long amount, [Remainder] IGuildUser receiver)
|
||||||
// return;
|
{
|
||||||
// }
|
var channel = (ITextChannel)umsg.Channel;
|
||||||
|
if (amount <= 0)
|
||||||
|
return;
|
||||||
|
var success = await CurrencyHandler.RemoveCurrencyAsync((IGuildUser)umsg.Author, $"Gift to {receiver.Username} ({receiver.Id}).", amount, true).ConfigureAwait(false);
|
||||||
|
if (!success)
|
||||||
|
{
|
||||||
|
await channel.SendMessageAsync($"{umsg.Author.Mention} You don't have enough {Gambling.CurrencyPluralName}.").ConfigureAwait(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await CurrencyHandler.AddCurrencyAsync(receiver, $"Gift from {umsg.Author.Username} ({umsg.Author.Id}).", amount, true).ConfigureAwait(false);
|
||||||
|
await channel.SendMessageAsync($"{umsg.Author.Mention} successfully sent {amount} {Gambling.CurrencyPluralName}s to {receiver.Mention}!").ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
// await FlowersHandler.RemoveFlowers(umsg.Author, "Gift", (int)amount, true).ConfigureAwait(false);
|
|
||||||
// await FlowersHandler.AddFlowersAsync(receiver, "Gift", (int)amount).ConfigureAwait(false);
|
|
||||||
|
|
||||||
// await channel.SendMessageAsync($"{umsg.Author.Mention} successfully sent {amount} {NadekoBot.Config.CurrencyName}s to {receiver.Mention}!").ConfigureAwait(false);
|
|
||||||
|
|
||||||
//}
|
|
||||||
|
|
||||||
////todo DB
|
|
||||||
////todo owner only
|
////todo owner only
|
||||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
//[RequireContext(ContextType.Guild)]
|
//[RequireContext(ContextType.Guild)]
|
||||||
//public Task Award(IUserMessage umsg, long amount, [Remainder] IGuildUser usr) =>
|
//public Task Award(IUserMessage umsg, long amount, [Remainder] IGuildUser usr) =>
|
||||||
// Award(umsg, amount, usr.Id);
|
// Award(umsg, amount, usr.Id);
|
||||||
|
|
||||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
//[RequireContext(ContextType.Guild)]
|
//[RequireContext(ContextType.Guild)]
|
||||||
//public async Task Award(IUserMessage umsg, long amount, [Remainder] ulong usrId)
|
//public async Task Award(IUserMessage umsg, long amount, [Remainder] ulong usrId)
|
||||||
//{
|
//{
|
||||||
@ -100,19 +97,19 @@ namespace NadekoBot.Modules.Gambling
|
|||||||
// if (amount <= 0)
|
// if (amount <= 0)
|
||||||
// return;
|
// return;
|
||||||
|
|
||||||
// await FlowersHandler.AddFlowersAsync(usrId, $"Awarded by bot owner. ({umsg.Author.Username}/{umsg.Author.Id})", (int)amount).ConfigureAwait(false);
|
// await CurrencyHandler.AddFlowersAsync(usrId, $"Awarded by bot owner. ({umsg.Author.Username}/{umsg.Author.Id})", (int)amount).ConfigureAwait(false);
|
||||||
|
|
||||||
// await channel.SendMessageAsync($"{umsg.Author.Mention} successfully awarded {amount} {NadekoBot.Config.CurrencyName}s to <@{usrId}>!").ConfigureAwait(false);
|
// await channel.SendMessageAsync($"{umsg.Author.Mention} successfully awarded {amount} {Gambling.CurrencyName}s to <@{usrId}>!").ConfigureAwait(false);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
////todo owner only
|
////todo owner only
|
||||||
////todo DB
|
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
|
||||||
//[RequireContext(ContextType.Guild)]
|
//[RequireContext(ContextType.Guild)]
|
||||||
//public Task Take(IUserMessage umsg, long amount, [Remainder] IGuildUser user) =>
|
//public Task Take(IUserMessage umsg, long amount, [Remainder] IGuildUser user) =>
|
||||||
// Take(umsg, amount, user.Id);
|
// Take(umsg, amount, user.Id);
|
||||||
|
|
||||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
//todo owner only
|
||||||
|
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
//[RequireContext(ContextType.Guild)]
|
//[RequireContext(ContextType.Guild)]
|
||||||
//public async Task Take(IUserMessage umsg, long amount, [Remainder] ulong usrId)
|
//public async Task Take(IUserMessage umsg, long amount, [Remainder] ulong usrId)
|
||||||
//{
|
//{
|
||||||
@ -120,76 +117,84 @@ namespace NadekoBot.Modules.Gambling
|
|||||||
// if (amount <= 0)
|
// if (amount <= 0)
|
||||||
// return;
|
// return;
|
||||||
|
|
||||||
// await FlowersHandler.RemoveFlowers(usrId, $"Taken by bot owner.({umsg.Author.Username}/{umsg.Author.Id})", (int)amount).ConfigureAwait(false);
|
// await CurrencyHandler.RemoveFlowers(usrId, $"Taken by bot owner.({umsg.Author.Username}/{umsg.Author.Id})", (int)amount).ConfigureAwait(false);
|
||||||
|
|
||||||
// await channel.SendMessageAsync($"{umsg.Author.Mention} successfully took {amount} {NadekoBot.Config.CurrencyName}s from <@{usrId}>!").ConfigureAwait(false);
|
// await channel.SendMessageAsync($"{umsg.Author.Mention} successfully took {amount} {Gambling.CurrencyName}s from <@{usrId}>!").ConfigureAwait(false);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
//[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
//public async Task BetRoll(IUserMessage umsg, int amount)
|
public async Task BetRoll(IUserMessage umsg, long amount)
|
||||||
//{
|
{
|
||||||
// var channel = (ITextChannel)umsg.Channel;
|
var channel = (ITextChannel)umsg.Channel;
|
||||||
|
|
||||||
// if (amount < 1)
|
if (amount < 1)
|
||||||
// return;
|
return;
|
||||||
|
|
||||||
// var userFlowers = GetUserFlowers(umsg.Author.Id);
|
var guildUser = (IGuildUser)umsg.Author;
|
||||||
|
|
||||||
// if (userFlowers < amount)
|
long userFlowers;
|
||||||
// {
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
// await channel.SendMessageAsync($"{umsg.Author.Mention} You don't have enough {NadekoBot.Config.CurrencyName}s. You only have {userFlowers}{NadekoBot.Config.CurrencySign}.").ConfigureAwait(false);
|
{
|
||||||
// return;
|
userFlowers = uow.Currency.GetOrCreate(umsg.Author.Id).Amount;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// await FlowersHandler.RemoveFlowers(umsg.Author, "Betroll Gamble", (int)amount, true).ConfigureAwait(false);
|
if (userFlowers < amount)
|
||||||
|
{
|
||||||
|
await channel.SendMessageAsync($"{guildUser.Mention} You don't have enough {Gambling.CurrencyPluralName}. You only have {userFlowers}{Gambling.CurrencySign}.").ConfigureAwait(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// var rng = new Random().Next(0, 101);
|
await CurrencyHandler.RemoveCurrencyAsync(guildUser, "Betroll Gamble", amount, false).ConfigureAwait(false);
|
||||||
// var str = $"{umsg.Author.Mention} `You rolled {rng}.` ";
|
|
||||||
// if (rng < 67)
|
|
||||||
// {
|
|
||||||
// str += "Better luck next time.";
|
|
||||||
// }
|
|
||||||
// else if (rng < 90)
|
|
||||||
// {
|
|
||||||
// str += $"Congratulations! You won {amount * 2}{NadekoBot.Config.CurrencySign} for rolling above 66";
|
|
||||||
// await FlowersHandler.AddFlowersAsync(umsg.Author, "Betroll Gamble", amount * 2, true).ConfigureAwait(false);
|
|
||||||
// }
|
|
||||||
// else if (rng < 100)
|
|
||||||
// {
|
|
||||||
// str += $"Congratulations! You won {amount * 3}{NadekoBot.Config.CurrencySign} for rolling above 90.";
|
|
||||||
// await FlowersHandler.AddFlowersAsync(umsg.Author, "Betroll Gamble", amount * 3, true).ConfigureAwait(false);
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// str += $"👑 Congratulations! You won {amount * 10}{NadekoBot.Config.CurrencySign} for rolling **100**. 👑";
|
|
||||||
// await FlowersHandler.AddFlowersAsync(umsg.Author, "Betroll Gamble", amount * 10, true).ConfigureAwait(false);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// await channel.SendMessageAsync(str).ConfigureAwait(false);
|
var rng = new NadekoRandom().Next(0, 101);
|
||||||
//}
|
var str = $"{guildUser.Mention} `You rolled {rng}.` ";
|
||||||
|
if (rng < 67)
|
||||||
|
{
|
||||||
|
str += "More luck next time.";
|
||||||
|
}
|
||||||
|
else if (rng < 90)
|
||||||
|
{
|
||||||
|
str += $"Congratulations! You won {amount * 2}{Gambling.CurrencySign} for rolling above 66";
|
||||||
|
await CurrencyHandler.AddCurrencyAsync(guildUser, "Betroll Gamble", amount * 2, false).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
else if (rng < 100)
|
||||||
|
{
|
||||||
|
str += $"Congratulations! You won {amount * 3}{Gambling.CurrencySign} for rolling above 90.";
|
||||||
|
await CurrencyHandler.AddCurrencyAsync(guildUser, "Betroll Gamble", amount * 3, false).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
str += $"👑 Congratulations! You won {amount * 10}{Gambling.CurrencySign} for rolling **100**. 👑";
|
||||||
|
await CurrencyHandler.AddCurrencyAsync(guildUser, "Betroll Gamble", amount * 10, false).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
////todo DB
|
await channel.SendMessageAsync(str).ConfigureAwait(false);
|
||||||
// [LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
}
|
||||||
// [RequireContext(ContextType.Guild)]
|
|
||||||
// public async Task Leaderboard(IUserMessage umsg)
|
|
||||||
// {
|
|
||||||
// var channel = (ITextChannel)umsg.Channel;
|
|
||||||
|
|
||||||
// var richestTemp = DbHandler.Instance.GetTopRichest();
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
// var richest = richestTemp as CurrencyState[] ?? richestTemp.ToArray();
|
[RequireContext(ContextType.Guild)]
|
||||||
// if (richest.Length == 0)
|
public async Task Leaderboard(IUserMessage umsg)
|
||||||
// return;
|
{
|
||||||
// await channel.SendMessageAsync(
|
var channel = (ITextChannel)umsg.Channel;
|
||||||
// richest.Aggregate(new StringBuilder(
|
|
||||||
//$@"```xl
|
IEnumerable<Currency> richest;
|
||||||
//┏━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━┓
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
//┃ Id ┃ $$$ ┃
|
{
|
||||||
//"),
|
richest = uow.Currency.GetTopRichest(10);
|
||||||
// (cur, cs) => cur.AppendLine(
|
}
|
||||||
//$@"┣━━━━━━━━━━━━━━━━━━━━━╋━━━━━━━┫
|
if (!richest.Any())
|
||||||
//┃{(e.Server.Users.Where(u => u.Id == (ulong)cs.UserId).FirstOrDefault()?.Name.TrimTo(18, true) ?? cs.UserId.ToString()),-20} ┃ {cs.Value,5} ┃")
|
return;
|
||||||
// ).ToString() + "┗━━━━━━━━━━━━━━━━━━━━━┻━━━━━━━┛```").ConfigureAwait(false);
|
await channel.SendMessageAsync(
|
||||||
//}
|
richest.Aggregate(new StringBuilder(
|
||||||
|
$@"```xl
|
||||||
|
┏━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━┓
|
||||||
|
┃ Id ┃ $$$ ┃
|
||||||
|
"),
|
||||||
|
(cur, cs) => cur.AppendLine(
|
||||||
|
$@"┣━━━━━━━━━━━━━━━━━━━━━╋━━━━━━━┫
|
||||||
|
┃{(channel.Guild.GetUser(cs.UserId)?.Username.TrimTo(18, true) ?? cs.UserId.ToString()),-20} ┃ {cs,5} ┃")
|
||||||
|
).ToString() + "┗━━━━━━━━━━━━━━━━━━━━━┻━━━━━━━┛```").ConfigureAwait(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,9 +10,9 @@ using System.Threading.Tasks;
|
|||||||
// because i don't want to waste my time on this cancerous command
|
// because i don't want to waste my time on this cancerous command
|
||||||
namespace NadekoBot.Modules.Games
|
namespace NadekoBot.Modules.Games
|
||||||
{
|
{
|
||||||
public partial class GamesModule
|
public partial class Games
|
||||||
{
|
{
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Leet(IUserMessage umsg, int level, [Remainder] string text = null)
|
public async Task Leet(IUserMessage umsg, int level, [Remainder] string text = null)
|
||||||
{
|
{
|
||||||
|
@ -1,168 +1,220 @@
|
|||||||
//using Discord;
|
using Discord;
|
||||||
//using Discord.Commands;
|
using Discord.Commands;
|
||||||
//using NadekoBot.Classes;
|
using Discord.WebSocket;
|
||||||
//using NadekoBot.Extensions;
|
using NadekoBot.Attributes;
|
||||||
//using NadekoBot.Modules.Permissions.Classes;
|
using NadekoBot.Extensions;
|
||||||
//using System;
|
using NadekoBot.Services;
|
||||||
//using System.Collections.Concurrent;
|
using NadekoBot.Services.Database;
|
||||||
//using System.Collections.Generic;
|
using System;
|
||||||
//using System.IO;
|
using System.Collections.Concurrent;
|
||||||
//using System.Linq;
|
using System.Collections.Generic;
|
||||||
//using System.Security.Cryptography;
|
using System.IO;
|
||||||
//using System.Threading;
|
using System.Linq;
|
||||||
//using System.Threading.Tasks;
|
using System.Security.Cryptography;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
////todo DI into partials
|
//todo rewrite
|
||||||
////todo DB
|
namespace NadekoBot.Modules.Games
|
||||||
//namespace NadekoBot.Modules.Games
|
{
|
||||||
//{
|
public partial class Games
|
||||||
// /// <summary>
|
{
|
||||||
// /// Flower picking/planting idea is given to me by its
|
/// <summary>
|
||||||
// /// inceptor Violent Crumble from Game Developers League discord server
|
/// Flower picking/planting idea is given to me by its
|
||||||
// /// (he has !cookie and !nom) Thanks a lot Violent!
|
/// inceptor Violent Crumble from Game Developers League discord server
|
||||||
// /// Check out GDL (its a growing gamedev community):
|
/// (he has !cookie and !nom) Thanks a lot Violent!
|
||||||
// /// https://discord.gg/0TYNJfCU4De7YIk8
|
/// Check out GDL (its a growing gamedev community):
|
||||||
// /// </summary>
|
/// https://discord.gg/0TYNJfCU4De7YIk8
|
||||||
// class PlantPick : DiscordCommand
|
/// </summary>
|
||||||
// {
|
[Group]
|
||||||
|
public class PlantPickCommands
|
||||||
|
{
|
||||||
|
|
||||||
// private Random rng;
|
private Random rng;
|
||||||
// public PlantPick(DiscordModule module) : base(module)
|
|
||||||
// {
|
|
||||||
// NadekoBot.Client.MessageReceived += PotentialFlowerGeneration;
|
|
||||||
// rng = new Random();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// private static readonly ConcurrentDictionary<ulong, DateTime> plantpickCooldowns = new ConcurrentDictionary<ulong, DateTime>();
|
private ConcurrentDictionary<ulong, bool> generationChannels = new ConcurrentDictionary<ulong, bool>();
|
||||||
|
//channelid/message
|
||||||
|
private ConcurrentDictionary<ulong, List<IUserMessage>> plantedFlowers = new ConcurrentDictionary<ulong, List<IUserMessage>>();
|
||||||
|
//channelId/last generation
|
||||||
|
private ConcurrentDictionary<ulong, DateTime> lastGenerations = new ConcurrentDictionary<ulong, DateTime>();
|
||||||
|
|
||||||
// private async void PotentialFlowerGeneration(object sender, Discord.MessageEventArgs e)
|
private float chance;
|
||||||
// {
|
private int cooldown;
|
||||||
// try
|
|
||||||
// {
|
|
||||||
// if (e.Server == null || e.Channel.IsPrivate || e.Message.IsAuthor)
|
|
||||||
// return;
|
|
||||||
// var config = Classes.SpecificConfigurations.Default.Of(e.Server.Id);
|
|
||||||
// var now = DateTime.Now;
|
|
||||||
// int cd;
|
|
||||||
// DateTime lastSpawned;
|
|
||||||
// if (config.GenerateCurrencyChannels.TryGetValue(e.Channel.Id, out cd))
|
|
||||||
// if (!plantpickCooldowns.TryGetValue(e.Channel.Id, out lastSpawned) || (lastSpawned + new TimeSpan(0, cd, 0)) < now)
|
|
||||||
// {
|
|
||||||
// var rnd = Math.Abs(rng.Next(0,101));
|
|
||||||
// if (rnd == 0)
|
|
||||||
// {
|
|
||||||
// var msgs = new[] { await e.Channel.SendFile(GetRandomCurrencyImagePath()), await channel.SendMessageAsync($"❗ A random {NadekoBot.Config.CurrencyName} appeared! Pick it up by typing `>pick`") };
|
|
||||||
// plantedFlowerChannels.AddOrUpdate(e.Channel.Id, msgs, (u, m) => { m.ForEach(async msgToDelete => { try { await msgToDelete.Delete(); } catch { } }); return msgs; });
|
|
||||||
// plantpickCooldowns.AddOrUpdate(e.Channel.Id, now, (i, d) => now);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// catch { }
|
|
||||||
// }
|
|
||||||
// //channelid/messageid pair
|
|
||||||
// ConcurrentDictionary<ulong, IEnumerable<Message>> plantedFlowerChannels = new ConcurrentDictionary<ulong, IEnumerable<Message>>();
|
|
||||||
|
|
||||||
// private SemaphoreSlim locker = new SemaphoreSlim(1,1);
|
public PlantPickCommands()
|
||||||
|
{
|
||||||
|
NadekoBot.Client.MessageReceived += PotentialFlowerGeneration;
|
||||||
|
rng = new NadekoRandom();
|
||||||
|
|
||||||
// internal override void Init(CommandGroupBuilder cgb)
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
// {
|
{
|
||||||
// cgb.CreateCommand(Module.Prefix + "pick")
|
var conf = uow.BotConfig.GetOrCreate();
|
||||||
// .Description($"Picks a flower planted in this channel. | `{Prefix}pick`")
|
var x =
|
||||||
// .Do(async e =>
|
generationChannels = new ConcurrentDictionary<ulong, bool>(uow.GuildConfigs.GetAll()
|
||||||
// {
|
.Where(c => c.GenerateCurrencyChannelId != null)
|
||||||
// IEnumerable<Message> msgs;
|
.ToDictionary(c => c.GenerateCurrencyChannelId.Value, c => true));
|
||||||
|
chance = conf.CurrencyGenerationChance;
|
||||||
|
cooldown = conf.CurrencyGenerationCooldown;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// await e.Message.Delete().ConfigureAwait(false);
|
private Task PotentialFlowerGeneration(IMessage imsg)
|
||||||
// if (!plantedFlowerChannels.TryRemove(e.Channel.Id, out msgs))
|
{
|
||||||
// return;
|
var msg = imsg as IUserMessage;
|
||||||
|
if (msg == null || msg.IsAuthor())
|
||||||
|
return Task.CompletedTask;
|
||||||
|
|
||||||
// foreach(var msgToDelete in msgs)
|
var channel = imsg.Channel as ITextChannel;
|
||||||
// await msgToDelete.Delete().ConfigureAwait(false);
|
if (channel == null)
|
||||||
|
return Task.CompletedTask;
|
||||||
|
|
||||||
// await FlowersHandler.AddFlowersAsync(umsg.Author, "Picked a flower.", 1, true).ConfigureAwait(false);
|
bool shouldGenerate;
|
||||||
// var msg = await channel.SendMessageAsync($"**{umsg.Author.Username}** picked a {NadekoBot.Config.CurrencyName}!").ConfigureAwait(false);
|
if (!generationChannels.TryGetValue(channel.Id, out shouldGenerate) || !shouldGenerate)
|
||||||
// ThreadPool.QueueUserWorkItem(async (state) =>
|
return Task.CompletedTask;
|
||||||
// {
|
|
||||||
// try
|
|
||||||
// {
|
|
||||||
// await Task.Delay(10000).ConfigureAwait(false);
|
|
||||||
// await msg.Delete().ConfigureAwait(false);
|
|
||||||
// }
|
|
||||||
// catch { }
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
|
|
||||||
// cgb.CreateCommand(Module.Prefix + "plant")
|
var t = Task.Run(async () =>
|
||||||
// .Description($"Spend a flower to plant it in this channel. (If bot is restarted or crashes, flower will be lost) | `{Prefix}plant`")
|
{
|
||||||
// .Do(async e =>
|
var lastGeneration = lastGenerations.GetOrAdd(channel.Id, DateTime.MinValue);
|
||||||
// {
|
|
||||||
// await locker.WaitAsync().ConfigureAwait(false);
|
|
||||||
// try
|
|
||||||
// {
|
|
||||||
// if (plantedFlowerChannels.ContainsKey(e.Channel.Id))
|
|
||||||
// {
|
|
||||||
// await channel.SendMessageAsync($"There is already a {NadekoBot.Config.CurrencyName} in this channel.").ConfigureAwait(false);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// var removed = await FlowersHandler.RemoveFlowers(umsg.Author, "Planted a flower.", 1, true).ConfigureAwait(false);
|
|
||||||
// if (!removed)
|
|
||||||
// {
|
|
||||||
// await channel.SendMessageAsync($"You don't have any {NadekoBot.Config.CurrencyName}s.").ConfigureAwait(false);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// var file = GetRandomCurrencyImagePath();
|
if (DateTime.Now - TimeSpan.FromSeconds(cooldown) < lastGeneration) //recently generated in this channel, don't generate again
|
||||||
// Message msg;
|
return;
|
||||||
// if (file == null)
|
|
||||||
// msg = await channel.SendMessageAsync(NadekoBot.Config.CurrencySign).ConfigureAwait(false);
|
|
||||||
// else
|
|
||||||
// msg = await e.Channel.SendFile(file).ConfigureAwait(false);
|
|
||||||
// var vowelFirst = new[] { 'a', 'e', 'i', 'o', 'u' }.Contains(NadekoBot.Config.CurrencyName[0]);
|
|
||||||
// var msg2 = await channel.SendMessageAsync($"Oh how Nice! **{umsg.Author.Username}** planted {(vowelFirst ? "an" : "a")} {NadekoBot.Config.CurrencyName}. Pick it using {Module.Prefix}pick").ConfigureAwait(false);
|
|
||||||
// plantedFlowerChannels.TryAdd(e.Channel.Id, new[] { msg, msg2 });
|
|
||||||
// }
|
|
||||||
// finally { locker.Release(); }
|
|
||||||
// });
|
|
||||||
|
|
||||||
// cgb.CreateCommand(Prefix + "gencurrency")
|
var num = rng.Next(1, 101) + chance * 100;
|
||||||
// .Alias(Prefix + "gc")
|
|
||||||
// .Description($"Toggles currency generation on this channel. Every posted message will have 2% chance to spawn a {NadekoBot.Config.CurrencyName}. Optional parameter cooldown time in minutes, 5 minutes by default. Requires Manage Messages permission. | `{Prefix}gc` or `{Prefix}gc 60`")
|
|
||||||
// .AddCheck(SimpleCheckers.ManageMessages())
|
|
||||||
// .Parameter("cd", ParameterType.Unparsed)
|
|
||||||
// .Do(async e =>
|
|
||||||
// {
|
|
||||||
// var cdStr = cd;
|
|
||||||
// int cd = 2;
|
|
||||||
// if (!int.TryParse(cdStr, out cd) || cd < 0)
|
|
||||||
// {
|
|
||||||
// cd = 2;
|
|
||||||
// }
|
|
||||||
// var config = SpecificConfigurations.Default.Of(e.Server.Id);
|
|
||||||
// int throwaway;
|
|
||||||
// if (config.GenerateCurrencyChannels.TryRemove(e.Channel.Id, out throwaway))
|
|
||||||
// {
|
|
||||||
// await channel.SendMessageAsync("`Currency generation disabled on this channel.`").ConfigureAwait(false);
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// if (config.GenerateCurrencyChannels.TryAdd(e.Channel.Id, cd))
|
|
||||||
// await channel.SendMessageAsync($"`Currency generation enabled on this channel. Cooldown is {cd} minutes.`").ConfigureAwait(false);
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
|
|
||||||
// private string GetRandomCurrencyImagePath() =>
|
if (num > 100)
|
||||||
// Directory.GetFiles("data/currency_images").OrderBy(s => rng.Next()).FirstOrDefault();
|
{
|
||||||
|
lastGenerations.AddOrUpdate(channel.Id, DateTime.Now, (id, old) => DateTime.Now);
|
||||||
|
//todo get prefix
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var sent = await channel.SendFileAsync(
|
||||||
|
GetRandomCurrencyImagePath(),
|
||||||
|
$"❗ A random { Gambling.Gambling.CurrencyName } appeared! Pick it up by typing `>pick`")
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
plantedFlowers.AddOrUpdate(channel.Id, new List<IUserMessage>() { sent }, (id, old) => { old.Add(sent); return old; });
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
|
||||||
// int GetRandomNumber()
|
}
|
||||||
// {
|
});
|
||||||
// using (var rg = RandomNumberGenerator.Create())
|
return Task.CompletedTask;
|
||||||
// {
|
}
|
||||||
// byte[] rno = new byte[4];
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
// rg.GetBytes(rno);
|
[RequireContext(ContextType.Guild)]
|
||||||
// int randomvalue = BitConverter.ToInt32(rno, 0);
|
public async Task Pick(IUserMessage imsg)
|
||||||
// return randomvalue;
|
{
|
||||||
// }
|
var channel = (ITextChannel)imsg.Channel;
|
||||||
// }
|
|
||||||
// }
|
if (!channel.Guild.GetCurrentUser().GetPermissions(channel).ManageMessages)
|
||||||
//}
|
{
|
||||||
|
await channel.SendMessageAsync("`I need manage channel permissions in order to process this command.`").ConfigureAwait(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<IUserMessage> msgs;
|
||||||
|
|
||||||
|
try { await imsg.DeleteAsync().ConfigureAwait(false); } catch { }
|
||||||
|
if (!plantedFlowers.TryRemove(channel.Id, out msgs))
|
||||||
|
return;
|
||||||
|
|
||||||
|
await Task.WhenAll(msgs.Select(toDelete => toDelete.DeleteAsync())).ConfigureAwait(false);
|
||||||
|
|
||||||
|
await CurrencyHandler.AddCurrencyAsync((IGuildUser)imsg.Author, "Picked flower(s).", msgs.Count, false).ConfigureAwait(false);
|
||||||
|
var msg = await channel.SendMessageAsync($"**{imsg.Author.Username}** picked {msgs.Count}{Gambling.Gambling.CurrencySign}!").ConfigureAwait(false);
|
||||||
|
var t = Task.Run(async () =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await Task.Delay(10000).ConfigureAwait(false);
|
||||||
|
await msg.DeleteAsync().ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
|
[RequireContext(ContextType.Guild)]
|
||||||
|
public async Task Plant(IUserMessage imsg)
|
||||||
|
{
|
||||||
|
var channel = (ITextChannel)imsg.Channel;
|
||||||
|
if (channel == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var removed = await CurrencyHandler.RemoveCurrencyAsync((IGuildUser)imsg.Author, "Planted a flower.", 1, false).ConfigureAwait(false);
|
||||||
|
if (!removed)
|
||||||
|
{
|
||||||
|
await channel.SendMessageAsync($"You don't have any {Gambling.Gambling.CurrencyPluralName}.").ConfigureAwait(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var file = GetRandomCurrencyImagePath();
|
||||||
|
IUserMessage msg;
|
||||||
|
var vowelFirst = new[] { 'a', 'e', 'i', 'o', 'u' }.Contains(Gambling.Gambling.CurrencyName[0]);
|
||||||
|
var msgToSend = $"Oh how Nice! **{imsg.Author.Username}** planted {(vowelFirst ? "an" : "a")} {Gambling.Gambling.CurrencyName}. Pick it using >pick";
|
||||||
|
if (file == null)
|
||||||
|
{
|
||||||
|
msg = await channel.SendMessageAsync(Gambling.Gambling.CurrencySign).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//todo add prefix
|
||||||
|
msg = await channel.SendFileAsync(file, msgToSend).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
plantedFlowers.AddOrUpdate(channel.Id, new List<IUserMessage>() { msg }, (id, old) => { old.Add(msg); return old; });
|
||||||
|
}
|
||||||
|
|
||||||
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
|
[RequireContext(ContextType.Guild)]
|
||||||
|
[RequirePermission(GuildPermission.ManageMessages)]
|
||||||
|
public async Task Gencurrency(IUserMessage imsg)
|
||||||
|
{
|
||||||
|
var channel = imsg.Channel as ITextChannel;
|
||||||
|
if (channel == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
bool enabled;
|
||||||
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
|
{
|
||||||
|
var guildConfig = uow.GuildConfigs.For(channel.Id);
|
||||||
|
|
||||||
|
if (guildConfig.GenerateCurrencyChannelId == null)
|
||||||
|
{
|
||||||
|
guildConfig.GenerateCurrencyChannelId = channel.Id;
|
||||||
|
generationChannels.TryAdd(channel.Id, true);
|
||||||
|
enabled = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
guildConfig.GenerateCurrencyChannelId = null;
|
||||||
|
bool throwaway;
|
||||||
|
generationChannels.TryRemove(channel.Id, out throwaway);
|
||||||
|
enabled = false;
|
||||||
|
}
|
||||||
|
await uow.CompleteAsync();
|
||||||
|
}
|
||||||
|
if (enabled)
|
||||||
|
{
|
||||||
|
await channel.SendMessageAsync("`Currency generation enabled on this channel.`").ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await channel.SendMessageAsync($"`Currency generation disabled on this channel.`").ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetRandomCurrencyImagePath() =>
|
||||||
|
Directory.GetFiles("data/currency_images").OrderBy(s => rng.Next()).FirstOrDefault();
|
||||||
|
|
||||||
|
int GetRandomNumber()
|
||||||
|
{
|
||||||
|
using (var rg = RandomNumberGenerator.Create())
|
||||||
|
{
|
||||||
|
byte[] rno = new byte[4];
|
||||||
|
rg.GetBytes(rno);
|
||||||
|
int randomvalue = BitConverter.ToInt32(rno, 0);
|
||||||
|
return randomvalue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -10,12 +10,11 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace NadekoBot.Modules.Games
|
namespace NadekoBot.Modules.Games
|
||||||
{
|
{
|
||||||
public partial class GamesModule
|
public partial class Games
|
||||||
{
|
{
|
||||||
//todo DB in the future
|
|
||||||
public static ConcurrentDictionary<IGuild, Poll> ActivePolls = new ConcurrentDictionary<IGuild, Poll>();
|
public static ConcurrentDictionary<IGuild, Poll> ActivePolls = new ConcurrentDictionary<IGuild, Poll>();
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Poll(IUserMessage umsg, [Remainder] string arg = null)
|
public async Task Poll(IUserMessage umsg, [Remainder] string arg = null)
|
||||||
{
|
{
|
||||||
@ -36,7 +35,7 @@ namespace NadekoBot.Modules.Games
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Pollend(IUserMessage umsg)
|
public async Task Pollend(IUserMessage umsg)
|
||||||
{
|
{
|
||||||
@ -108,18 +107,26 @@ namespace NadekoBot.Modules.Games
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task Vote(IMessage imsg)
|
private Task Vote(IMessage imsg)
|
||||||
{
|
{
|
||||||
var msg = imsg as ISystemMessage;
|
// has to be a user message
|
||||||
|
var msg = imsg as IUserMessage;
|
||||||
if (msg == null)
|
if (msg == null)
|
||||||
return;
|
return Task.CompletedTask;
|
||||||
try
|
// channel must be private
|
||||||
{
|
|
||||||
IPrivateChannel ch;
|
IPrivateChannel ch;
|
||||||
if ((ch = msg.Channel as IPrivateChannel) == null)
|
if ((ch = msg.Channel as IPrivateChannel) == null)
|
||||||
return;
|
return Task.CompletedTask;
|
||||||
|
|
||||||
|
// has to be an integer
|
||||||
int vote;
|
int vote;
|
||||||
if (!int.TryParse(msg.Content, out vote)) return;
|
if (!int.TryParse(msg.Content, out vote)) return Task.CompletedTask;
|
||||||
|
|
||||||
|
var t = Task.Run(async () =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
if (vote < 1 || vote > answers.Length)
|
if (vote < 1 || vote > answers.Length)
|
||||||
return;
|
return;
|
||||||
if (participants.TryAdd(msg.Author, vote))
|
if (participants.TryAdd(msg.Author, vote))
|
||||||
@ -128,6 +135,8 @@ namespace NadekoBot.Modules.Games
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
|
});
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,196 +1,197 @@
|
|||||||
//using Discord;
|
using Discord;
|
||||||
//using Discord.Commands;
|
using Discord.Commands;
|
||||||
//using NadekoBot.Classes;
|
using Discord.WebSocket;
|
||||||
//using NadekoBot.DataModels;
|
using NadekoBot.Attributes;
|
||||||
//using NadekoBot.Extensions;
|
using NadekoBot.Extensions;
|
||||||
//using System;
|
using NadekoBot.Services;
|
||||||
//using System.Collections.Concurrent;
|
using NadekoBot.Services.Database;
|
||||||
//using System.Collections.Generic;
|
using System;
|
||||||
//using System.Diagnostics;
|
using System.Collections.Concurrent;
|
||||||
//using System.Linq;
|
using System.Collections.Generic;
|
||||||
//using System.Threading.Tasks;
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
////todo DB
|
namespace NadekoBot.Modules.Games
|
||||||
////todo Rewrite?
|
{
|
||||||
//namespace NadekoBot.Modules.Games
|
public partial class Games
|
||||||
//{
|
{
|
||||||
// public static class SentencesProvider
|
public class TypingGame
|
||||||
// {
|
{
|
||||||
// internal static string GetRandomSentence()
|
public const float WORD_VALUE = 4.5f;
|
||||||
// {
|
private readonly ITextChannel channel;
|
||||||
// var data = DbHandler.Instance.GetAllRows<TypingArticle>();
|
public string CurrentSentence;
|
||||||
// try
|
public bool IsActive;
|
||||||
// {
|
private readonly Stopwatch sw;
|
||||||
// return data.ToList()[new Random().Next(0, data.Count())].Text;
|
private readonly List<ulong> finishedUserIds;
|
||||||
// }
|
|
||||||
// catch
|
|
||||||
// {
|
|
||||||
// return "Failed retrieving data from parse. Owner didn't add any articles to type using `typeadd`.";
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public class TypingGame
|
public TypingGame(ITextChannel channel)
|
||||||
// {
|
{
|
||||||
// public const float WORD_VALUE = 4.5f;
|
this.channel = channel;
|
||||||
// private readonly Channel channel;
|
IsActive = false;
|
||||||
// public string CurrentSentence;
|
sw = new Stopwatch();
|
||||||
// public bool IsActive;
|
finishedUserIds = new List<ulong>();
|
||||||
// private readonly Stopwatch sw;
|
}
|
||||||
// private readonly List<ulong> finishedUserIds;
|
|
||||||
|
|
||||||
// public TypingGame(Channel channel)
|
public ITextChannel Channel { get; set; }
|
||||||
// {
|
|
||||||
// this.channel = channel;
|
|
||||||
// IsActive = false;
|
|
||||||
// sw = new Stopwatch();
|
|
||||||
// finishedUserIds = new List<ulong>();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public Channel Channell { get; internal set; }
|
public async Task<bool> Stop()
|
||||||
|
{
|
||||||
|
if (!IsActive) return false;
|
||||||
|
NadekoBot.Client.MessageReceived -= AnswerReceived;
|
||||||
|
finishedUserIds.Clear();
|
||||||
|
IsActive = false;
|
||||||
|
sw.Stop();
|
||||||
|
sw.Reset();
|
||||||
|
await channel.SendMessageAsync("Typing contest stopped").ConfigureAwait(false);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// internal async Task<bool> Stop()
|
public async Task Start()
|
||||||
// {
|
{
|
||||||
// if (!IsActive) return false;
|
while (true)
|
||||||
// NadekoBot.Client.MessageReceived -= AnswerReceived;
|
{
|
||||||
// finishedUserIds.Clear();
|
if (IsActive) return; // can't start running game
|
||||||
// IsActive = false;
|
IsActive = true;
|
||||||
// sw.Stop();
|
CurrentSentence = GetRandomSentence();
|
||||||
// sw.Reset();
|
var i = (int)(CurrentSentence.Length / WORD_VALUE * 1.7f);
|
||||||
// await channel.Send("Typing contest stopped").ConfigureAwait(false);
|
await channel.SendMessageAsync($":clock2: Next contest will last for {i} seconds. Type the bolded text as fast as you can.").ConfigureAwait(false);
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// internal async Task Start()
|
|
||||||
// {
|
|
||||||
// while (true)
|
|
||||||
// {
|
|
||||||
// if (IsActive) return; // can't start running game
|
|
||||||
// IsActive = true;
|
|
||||||
// CurrentSentence = SentencesProvider.GetRandomSentence();
|
|
||||||
// var i = (int)(CurrentSentence.Length / WORD_VALUE * 1.7f);
|
|
||||||
// await channel.SendMessageAsync($":clock2: Next contest will last for {i} seconds. Type the bolded text as fast as you can.").ConfigureAwait(false);
|
|
||||||
|
|
||||||
|
|
||||||
// var msg = await channel.SendMessageAsync("Starting new typing contest in **3**...").ConfigureAwait(false);
|
var msg = await channel.SendMessageAsync("Starting new typing contest in **3**...").ConfigureAwait(false);
|
||||||
// await Task.Delay(1000).ConfigureAwait(false);
|
await Task.Delay(1000).ConfigureAwait(false);
|
||||||
// await msg.Edit("Starting new typing contest in **2**...").ConfigureAwait(false);
|
await msg.ModifyAsync(m => m.Content = "Starting new typing contest in **2**...").ConfigureAwait(false);
|
||||||
// await Task.Delay(1000).ConfigureAwait(false);
|
await Task.Delay(1000).ConfigureAwait(false);
|
||||||
// await msg.Edit("Starting new typing contest in **1**...").ConfigureAwait(false);
|
await msg.ModifyAsync(m => m.Content = "Starting new typing contest in **1**...").ConfigureAwait(false);
|
||||||
// await Task.Delay(1000).ConfigureAwait(false);
|
await Task.Delay(1000).ConfigureAwait(false);
|
||||||
// await msg.Edit($":book:**{CurrentSentence.Replace(" ", " \x200B")}**:book:").ConfigureAwait(false);
|
await msg.ModifyAsync(m => m.Content = $":book:**{CurrentSentence.Replace(" ", " \x200B")}**:book:").ConfigureAwait(false);
|
||||||
// sw.Start();
|
sw.Start();
|
||||||
// HandleAnswers();
|
HandleAnswers();
|
||||||
|
|
||||||
// while (i > 0)
|
while (i > 0)
|
||||||
|
{
|
||||||
|
await Task.Delay(1000).ConfigureAwait(false);
|
||||||
|
i--;
|
||||||
|
if (!IsActive)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await Stop().ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetRandomSentence()
|
||||||
|
{
|
||||||
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
|
{
|
||||||
|
return uow.TypingArticles.GetRandom()?.Text ?? "No typing articles found. Use `>typeadd` command to add a new article for typing.";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HandleAnswers()
|
||||||
|
{
|
||||||
|
NadekoBot.Client.MessageReceived += AnswerReceived;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Task AnswerReceived(IMessage imsg)
|
||||||
|
{
|
||||||
|
var msg = imsg as IUserMessage;
|
||||||
|
if (msg == null)
|
||||||
|
return Task.CompletedTask;
|
||||||
|
var t = Task.Run(async () =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (channel == null || channel.Id != channel.Id || msg.Author.Id == NadekoBot.Client.GetCurrentUser().Id) return;
|
||||||
|
|
||||||
|
var guess = msg.Content;
|
||||||
|
|
||||||
|
var distance = CurrentSentence.LevenshteinDistance(guess);
|
||||||
|
var decision = Judge(distance, guess.Length);
|
||||||
|
if (decision && !finishedUserIds.Contains(msg.Author.Id))
|
||||||
|
{
|
||||||
|
finishedUserIds.Add(msg.Author.Id);
|
||||||
|
await channel.SendMessageAsync($"{msg.Author.Mention} finished in **{sw.Elapsed.Seconds}** seconds with { distance } errors, **{ CurrentSentence.Length / WORD_VALUE / sw.Elapsed.Seconds * 60 }** WPM!").ConfigureAwait(false);
|
||||||
|
if (finishedUserIds.Count % 2 == 0)
|
||||||
|
{
|
||||||
|
await channel.SendMessageAsync($":exclamation: `A lot of people finished, here is the text for those still typing:`\n\n:book:**{CurrentSentence}**:book:").ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
});
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool Judge(int errors, int textLength) => errors <= textLength / 25;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[Group]
|
||||||
|
public class SpeedTypingCommands
|
||||||
|
{
|
||||||
|
|
||||||
|
public static ConcurrentDictionary<ulong, TypingGame> RunningContests;
|
||||||
|
|
||||||
|
public SpeedTypingCommands()
|
||||||
|
{
|
||||||
|
RunningContests = new ConcurrentDictionary<ulong, TypingGame>();
|
||||||
|
}
|
||||||
|
|
||||||
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
|
[RequireContext(ContextType.Guild)]
|
||||||
|
public async Task TypeStart(IUserMessage msg)
|
||||||
|
{
|
||||||
|
var channel = (ITextChannel)msg.Channel;
|
||||||
|
|
||||||
|
var game = RunningContests.GetOrAdd(channel.Guild.Id, id => new TypingGame(channel));
|
||||||
|
|
||||||
|
if (game.IsActive)
|
||||||
|
{
|
||||||
|
await channel.SendMessageAsync(
|
||||||
|
$"Contest already running in " +
|
||||||
|
$"{game.Channel.Mention} channel.")
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await game.Start().ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
|
[RequireContext(ContextType.Guild)]
|
||||||
|
public async Task TypeStop(IUserMessage imsg)
|
||||||
|
{
|
||||||
|
var channel = (ITextChannel)imsg.Channel;
|
||||||
|
TypingGame game;
|
||||||
|
if (RunningContests.TryRemove(channel.Guild.Id, out game))
|
||||||
|
{
|
||||||
|
await game.Stop().ConfigureAwait(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await channel.SendMessageAsync("No contest to stop on this channel.").ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
////todo owner only
|
||||||
|
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
|
//[RequireContext(ContextType.Guild)]
|
||||||
|
//public async Task Typeadd(IUserMessage imsg, [Remainder] string text)
|
||||||
//{
|
//{
|
||||||
// await Task.Delay(1000).ConfigureAwait(false);
|
// var channel = (ITextChannel)imsg.Channel;
|
||||||
// i--;
|
|
||||||
// if (!IsActive)
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// await Stop().ConfigureAwait(false);
|
// using (var uow = DbHandler.UnitOfWork())
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// private void HandleAnswers()
|
|
||||||
// {
|
// {
|
||||||
// NadekoBot.Client.MessageReceived += AnswerReceived;
|
// uow.TypingArticles.Add(new Services.Database.Models.TypingArticle
|
||||||
// }
|
|
||||||
|
|
||||||
// private async void AnswerReceived(object sender, MessageEventArgs e)
|
|
||||||
// {
|
// {
|
||||||
// try
|
// Author = imsg.Author.Username,
|
||||||
// {
|
// Text = text
|
||||||
// if (e.Channel == null || e.Channel.Id != channel.Id || umsg.Author.Id == NadekoBot.Client.CurrentUser.Id) return;
|
|
||||||
|
|
||||||
// var guess = e.Message.RawText;
|
|
||||||
|
|
||||||
// var distance = CurrentSentence.LevenshteinDistance(guess);
|
|
||||||
// var decision = Judge(distance, guess.Length);
|
|
||||||
// if (decision && !finishedUserIds.Contains(umsg.Author.Id))
|
|
||||||
// {
|
|
||||||
// finishedUserIds.Add(umsg.Author.Id);
|
|
||||||
// await channel.Send($"{umsg.Author.Mention} finished in **{sw.Elapsed.Seconds}** seconds with { distance } errors, **{ CurrentSentence.Length / WORD_VALUE / sw.Elapsed.Seconds * 60 }** WPM!").ConfigureAwait(false);
|
|
||||||
// if (finishedUserIds.Count % 2 == 0)
|
|
||||||
// {
|
|
||||||
// await channel.SendMessageAsync($":exclamation: `A lot of people finished, here is the text for those still typing:`\n\n:book:**{CurrentSentence}**:book:").ConfigureAwait(false);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// catch { }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// private bool Judge(int errors, int textLength) => errors <= textLength / 25;
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
// internal class SpeedTyping : DiscordCommand
|
|
||||||
// {
|
|
||||||
|
|
||||||
// public static ConcurrentDictionary<ulong, TypingGame> RunningContests;
|
|
||||||
|
|
||||||
// public SpeedTyping(DiscordModule module) : base(module)
|
|
||||||
// {
|
|
||||||
// RunningContests = new ConcurrentDictionary<ulong, TypingGame>();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public Func<CommandEventArgs, Task> DoFunc() =>
|
|
||||||
// async e =>
|
|
||||||
// {
|
|
||||||
// var game = RunningContests.GetOrAdd(umsg.Author.Server.Id, id => new TypingGame(e.Channel));
|
|
||||||
|
|
||||||
// if (game.IsActive)
|
|
||||||
// {
|
|
||||||
// await channel.SendMessageAsync(
|
|
||||||
// $"Contest already running in " +
|
|
||||||
// $"{game.Channell.Mention} channel.")
|
|
||||||
// .ConfigureAwait(false);
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// await game.Start().ConfigureAwait(false);
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
|
||||||
// private Func<CommandEventArgs, Task> QuitFunc() =>
|
|
||||||
// async e =>
|
|
||||||
// {
|
|
||||||
// TypingGame game;
|
|
||||||
// if (RunningContests.TryRemove(umsg.Author.Server.Id, out game))
|
|
||||||
// {
|
|
||||||
// await game.Stop().ConfigureAwait(false);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// await channel.SendMessageAsync("No contest to stop on this channel.").ConfigureAwait(false);
|
|
||||||
// };
|
|
||||||
|
|
||||||
// internal override void Init(CommandGroupBuilder cgb)
|
|
||||||
// {
|
|
||||||
// cgb.CreateCommand(Module.Prefix + "typestart")
|
|
||||||
// .Description($"Starts a typing contest. | `{Prefix}typestart`")
|
|
||||||
// .Do(DoFunc());
|
|
||||||
|
|
||||||
// cgb.CreateCommand(Module.Prefix + "typestop")
|
|
||||||
// .Description($"Stops a typing contest on the current channel. | `{Prefix}typestop`")
|
|
||||||
// .Do(QuitFunc());
|
|
||||||
|
|
||||||
// cgb.CreateCommand(Module.Prefix + "typeadd")
|
|
||||||
// .Description($"Adds a new article to the typing contest. Owner only. | `{Prefix}typeadd wordswords`")
|
|
||||||
// .Parameter("text", ParameterType.Unparsed)
|
|
||||||
// .Do(async e =>
|
|
||||||
// {
|
|
||||||
// if (!NadekoBot.IsOwner(umsg.Author.Id) || string.IsNullOrWhiteSpace(text)) return;
|
|
||||||
|
|
||||||
// DbHandler.Instance.Connection.Insert(new TypingArticle
|
|
||||||
// {
|
|
||||||
// Text = text,
|
|
||||||
// DateAdded = DateTime.Now
|
|
||||||
// });
|
// });
|
||||||
|
// }
|
||||||
|
|
||||||
// await channel.SendMessageAsync("Added new article for typing game.").ConfigureAwait(false);
|
// await channel.SendMessageAsync("Added new article for typing game.").ConfigureAwait(false);
|
||||||
// });
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//}
|
//}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -7,8 +7,6 @@ using System.Text;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
// todo rewrite?
|
|
||||||
// todo DB
|
|
||||||
namespace NadekoBot.Modules.Games.Trivia
|
namespace NadekoBot.Modules.Games.Trivia
|
||||||
{
|
{
|
||||||
public class TriviaGame
|
public class TriviaGame
|
||||||
@ -102,12 +100,13 @@ namespace NadekoBot.Modules.Games.Trivia
|
|||||||
ShouldStopGame = true;
|
ShouldStopGame = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task PotentialGuess(IMessage imsg)
|
private Task PotentialGuess(IMessage imsg)
|
||||||
{
|
{
|
||||||
var umsg = imsg as IUserMessage;
|
var umsg = imsg as IUserMessage;
|
||||||
if (umsg == null)
|
if (umsg == null)
|
||||||
return;
|
return Task.CompletedTask;
|
||||||
|
var t = Task.Run(async () =>
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!(umsg.Channel is IGuildChannel && umsg.Channel is ITextChannel)) return;
|
if (!(umsg.Channel is IGuildChannel && umsg.Channel is ITextChannel)) return;
|
||||||
@ -135,6 +134,8 @@ namespace NadekoBot.Modules.Games.Trivia
|
|||||||
await channel.SendMessageAsync($":exclamation: We have a winner! It's {guildUser.Mention}.").ConfigureAwait(false);
|
await channel.SendMessageAsync($":exclamation: We have a winner! It's {guildUser.Mention}.").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
|
});
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetLeaderboard()
|
public string GetLeaderboard()
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using Newtonsoft.Json.Linq;
|
using NadekoBot.Services;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
@ -9,10 +10,9 @@ namespace NadekoBot.Modules.Games.Trivia
|
|||||||
public class TriviaQuestionPool
|
public class TriviaQuestionPool
|
||||||
{
|
{
|
||||||
public static TriviaQuestionPool Instance { get; } = new TriviaQuestionPool();
|
public static TriviaQuestionPool Instance { get; } = new TriviaQuestionPool();
|
||||||
//todo DB
|
|
||||||
public HashSet<TriviaQuestion> pool = new HashSet<TriviaQuestion>();
|
public HashSet<TriviaQuestion> pool = new HashSet<TriviaQuestion>();
|
||||||
|
|
||||||
private Random rng { get; } = new Random();
|
private Random rng { get; } = new NadekoRandom();
|
||||||
|
|
||||||
static TriviaQuestionPool() { }
|
static TriviaQuestionPool() { }
|
||||||
|
|
||||||
@ -28,16 +28,16 @@ namespace NadekoBot.Modules.Games.Trivia
|
|||||||
return list[rand];
|
return list[rand];
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void Reload()
|
public void Reload()
|
||||||
{
|
{
|
||||||
var arr = JArray.Parse(File.ReadAllText("data/questions.json"));
|
var arr = JArray.Parse(File.ReadAllText("data/triviaquestions.json"));
|
||||||
|
|
||||||
foreach (var item in arr)
|
foreach (var item in arr)
|
||||||
{
|
{
|
||||||
var tq = new TriviaQuestion(item["Question"].ToString(), item["Answer"].ToString(), item["Category"]?.ToString());
|
var tq = new TriviaQuestion(item["Question"].ToString(), item["Answer"].ToString(), item["Category"]?.ToString());
|
||||||
pool.Add(tq);
|
pool.Add(tq);
|
||||||
}
|
}
|
||||||
var r = new Random();
|
var r = new NadekoRandom();
|
||||||
pool = new HashSet<TriviaQuestion>(pool.OrderBy(x => r.Next()));
|
pool = new HashSet<TriviaQuestion>(pool.OrderBy(x => r.Next()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,16 +10,16 @@ using System.Threading.Tasks;
|
|||||||
//todo Rewrite? Fix trivia not stopping bug
|
//todo Rewrite? Fix trivia not stopping bug
|
||||||
namespace NadekoBot.Modules.Games
|
namespace NadekoBot.Modules.Games
|
||||||
{
|
{
|
||||||
public partial class GamesModule
|
public partial class Games
|
||||||
{
|
{
|
||||||
[Group]
|
[Group]
|
||||||
public class TriviaCommands
|
public class TriviaCommands
|
||||||
{
|
{
|
||||||
public static ConcurrentDictionary<ulong, TriviaGame> RunningTrivias = new ConcurrentDictionary<ulong, TriviaGame>();
|
public static ConcurrentDictionary<ulong, TriviaGame> RunningTrivias = new ConcurrentDictionary<ulong, TriviaGame>();
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Trivia(IUserMessage umsg, string[] args)
|
public async Task Trivia(IUserMessage umsg, params string[] args)
|
||||||
{
|
{
|
||||||
var channel = (ITextChannel)umsg.Channel;
|
var channel = (ITextChannel)umsg.Channel;
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ namespace NadekoBot.Modules.Games
|
|||||||
await channel.SendMessageAsync("Trivia game is already running on this server.\n" + trivia.CurrentQuestion).ConfigureAwait(false);
|
await channel.SendMessageAsync("Trivia game is already running on this server.\n" + trivia.CurrentQuestion).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Tl(IUserMessage umsg)
|
public async Task Tl(IUserMessage umsg)
|
||||||
{
|
{
|
||||||
@ -57,7 +57,7 @@ namespace NadekoBot.Modules.Games
|
|||||||
await channel.SendMessageAsync("No trivia is running on this server.").ConfigureAwait(false);
|
await channel.SendMessageAsync("No trivia is running on this server.").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Tq(IUserMessage umsg)
|
public async Task Tq(IUserMessage umsg)
|
||||||
{
|
{
|
||||||
|
@ -12,10 +12,9 @@ using NadekoBot.Services.Database;
|
|||||||
|
|
||||||
namespace NadekoBot.Modules.Games
|
namespace NadekoBot.Modules.Games
|
||||||
{
|
{
|
||||||
[Module(">", AppendSpace = false)]
|
[NadekoModule("Games", ">")]
|
||||||
public partial class Games : DiscordModule
|
public partial class Games : DiscordModule
|
||||||
{
|
{
|
||||||
//todo DB
|
|
||||||
private IEnumerable<string> _8BallResponses {
|
private IEnumerable<string> _8BallResponses {
|
||||||
get {
|
get {
|
||||||
using (var uow = DbHandler.UnitOfWork())
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
@ -28,7 +27,7 @@ namespace NadekoBot.Modules.Games
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Choose(IUserMessage umsg, [Remainder] string list = null)
|
public async Task Choose(IUserMessage umsg, [Remainder] string list = null)
|
||||||
{
|
{
|
||||||
@ -38,11 +37,11 @@ namespace NadekoBot.Modules.Games
|
|||||||
var listArr = list.Split(';');
|
var listArr = list.Split(';');
|
||||||
if (listArr.Count() < 2)
|
if (listArr.Count() < 2)
|
||||||
return;
|
return;
|
||||||
var rng = new Random();
|
var rng = new NadekoRandom();
|
||||||
await channel.SendMessageAsync(listArr[rng.Next(0, listArr.Length)]).ConfigureAwait(false);
|
await channel.SendMessageAsync(listArr[rng.Next(0, listArr.Length)]).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task _8Ball(IUserMessage umsg, [Remainder] string question = null)
|
public async Task _8Ball(IUserMessage umsg, [Remainder] string question = null)
|
||||||
{
|
{
|
||||||
@ -50,12 +49,12 @@ namespace NadekoBot.Modules.Games
|
|||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(question))
|
if (string.IsNullOrWhiteSpace(question))
|
||||||
return;
|
return;
|
||||||
var rng = new Random();
|
var rng = new NadekoRandom();
|
||||||
await channel.SendMessageAsync($@":question: `Question` __**{question}**__
|
await channel.SendMessageAsync($@":question: `Question` __**{question}**__
|
||||||
🎱 `8Ball Answers` __**{_8BallResponses.Shuffle().FirstOrDefault()}**__").ConfigureAwait(false);
|
🎱 `8Ball Answers` __**{_8BallResponses.Shuffle().FirstOrDefault()}**__").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Rps(IUserMessage umsg, string input)
|
public async Task Rps(IUserMessage umsg, string input)
|
||||||
{
|
{
|
||||||
@ -91,7 +90,7 @@ namespace NadekoBot.Modules.Games
|
|||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var nadekoPick = new Random().Next(0, 3);
|
var nadekoPick = new NadekoRandom().Next(0, 3);
|
||||||
var msg = "";
|
var msg = "";
|
||||||
if (pick == nadekoPick)
|
if (pick == nadekoPick)
|
||||||
msg = $"It's a draw! Both picked :{GetRPSPick(pick)}:";
|
msg = $"It's a draw! Both picked :{GetRPSPick(pick)}:";
|
||||||
@ -105,7 +104,7 @@ namespace NadekoBot.Modules.Games
|
|||||||
await channel.SendMessageAsync(msg).ConfigureAwait(false);
|
await channel.SendMessageAsync(msg).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Linux(IUserMessage umsg, string guhnoo, string loonix)
|
public async Task Linux(IUserMessage umsg, string guhnoo, string loonix)
|
||||||
{
|
{
|
||||||
|
@ -12,7 +12,7 @@ using Discord.WebSocket;
|
|||||||
|
|
||||||
namespace NadekoBot.Modules.Help
|
namespace NadekoBot.Modules.Help
|
||||||
{
|
{
|
||||||
[Module("-", AppendSpace = false)]
|
[NadekoModule("Help", "-")]
|
||||||
public partial class Help : DiscordModule
|
public partial class Help : DiscordModule
|
||||||
{
|
{
|
||||||
public string HelpString {
|
public string HelpString {
|
||||||
@ -25,7 +25,7 @@ namespace NadekoBot.Modules.Help
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Modules(IUserMessage umsg)
|
public async Task Modules(IUserMessage umsg)
|
||||||
{
|
{
|
||||||
@ -35,7 +35,7 @@ namespace NadekoBot.Modules.Help
|
|||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Commands(IUserMessage umsg, [Remainder] string module = null)
|
public async Task Commands(IUserMessage umsg, [Remainder] string module = null)
|
||||||
{
|
{
|
||||||
@ -44,7 +44,7 @@ namespace NadekoBot.Modules.Help
|
|||||||
module = module?.Trim().ToUpperInvariant();
|
module = module?.Trim().ToUpperInvariant();
|
||||||
if (string.IsNullOrWhiteSpace(module))
|
if (string.IsNullOrWhiteSpace(module))
|
||||||
return;
|
return;
|
||||||
var cmds = _commands.Commands.Where(c => c.Module.Name.ToUpperInvariant() == module)
|
var cmds = _commands.Commands.Where(c => c.Module.Name.ToUpperInvariant().StartsWith(module))
|
||||||
.OrderBy(c => c.Text)
|
.OrderBy(c => c.Text)
|
||||||
.AsEnumerable();
|
.AsEnumerable();
|
||||||
var cmdsArray = cmds as Command[] ?? cmds.ToArray();
|
var cmdsArray = cmds as Command[] ?? cmds.ToArray();
|
||||||
@ -55,8 +55,7 @@ namespace NadekoBot.Modules.Help
|
|||||||
}
|
}
|
||||||
if (module != "customreactions" && module != "conversations")
|
if (module != "customreactions" && module != "conversations")
|
||||||
{
|
{
|
||||||
//todo aliases
|
await channel.SendTableAsync("`List Of Commands:`\n", cmdsArray, el => $"{el.Text,-15} {"["+el.Aliases.Skip(1).FirstOrDefault()+"]",-8}").ConfigureAwait(false);
|
||||||
await channel.SendTableAsync("`List Of Commands:`\n", cmdsArray, el => $"{el.Text,-15}").ConfigureAwait(false);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -65,7 +64,7 @@ namespace NadekoBot.Modules.Help
|
|||||||
await channel.SendMessageAsync($"`You can type \"-h command_name\" to see the help about that specific command.`").ConfigureAwait(false);
|
await channel.SendMessageAsync($"`You can type \"-h command_name\" to see the help about that specific command.`").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task H(IUserMessage umsg, [Remainder] string comToFind = null)
|
public async Task H(IUserMessage umsg, [Remainder] string comToFind = null)
|
||||||
{
|
{
|
||||||
@ -77,16 +76,23 @@ namespace NadekoBot.Modules.Help
|
|||||||
await (await (umsg.Author as IGuildUser).CreateDMChannelAsync()).SendMessageAsync(HelpString).ConfigureAwait(false);
|
await (await (umsg.Author as IGuildUser).CreateDMChannelAsync()).SendMessageAsync(HelpString).ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var com = _commands.Commands.FirstOrDefault(c => c.Text.ToLowerInvariant() == comToFind);
|
var com = _commands.Commands.FirstOrDefault(c => c.Text.ToLowerInvariant() == comToFind || c.Aliases.Select(a=>a.ToLowerInvariant()).Contains(comToFind));
|
||||||
|
|
||||||
//todo aliases
|
if (com == null)
|
||||||
|
{
|
||||||
|
await channel.SendMessageAsync("`No command found.`");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var str = $"**__Help for:__ `{com.Text}`**";
|
||||||
|
var alias = com.Aliases.Skip(1).FirstOrDefault();
|
||||||
|
if (alias != null)
|
||||||
|
str += $" / `{ alias }`";
|
||||||
if (com != null)
|
if (com != null)
|
||||||
await channel.SendMessageAsync($@"**__Help for:__ `{com.Text}`**
|
await channel.SendMessageAsync(str + $@"{Environment.NewLine}**Desc:** {com.Description}
|
||||||
**Desc:** {com.Description}
|
|
||||||
**Usage:** {com.Summary}").ConfigureAwait(false);
|
**Usage:** {com.Summary}").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Hgit(IUserMessage umsg)
|
public async Task Hgit(IUserMessage umsg)
|
||||||
{
|
{
|
||||||
@ -102,8 +108,7 @@ namespace NadekoBot.Modules.Help
|
|||||||
helpstr.AppendLine("----------------|--------------|-------");
|
helpstr.AppendLine("----------------|--------------|-------");
|
||||||
lastModule = com.Module.Name;
|
lastModule = com.Module.Name;
|
||||||
}
|
}
|
||||||
//todo aliases
|
helpstr.AppendLine($"`{com.Text}` {string.Join(" ", com.Aliases.Skip(1).Select(a=>"`"+a+"`"))} | {com.Description} | {com.Summary}");
|
||||||
helpstr.AppendLine($"`{com.Text}` | {com.Description} | {com.Summary}");
|
|
||||||
}
|
}
|
||||||
helpstr = helpstr.Replace((await NadekoBot.Client.GetCurrentUserAsync()).Username , "@BotName");
|
helpstr = helpstr.Replace((await NadekoBot.Client.GetCurrentUserAsync()).Username , "@BotName");
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
@ -113,7 +118,7 @@ namespace NadekoBot.Modules.Help
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Guide(IUserMessage umsg)
|
public async Task Guide(IUserMessage umsg)
|
||||||
{
|
{
|
||||||
@ -124,7 +129,7 @@ namespace NadekoBot.Modules.Help
|
|||||||
**Hosting Guides and docs can be found here**: <http://nadekobot.rtfd.io>").ConfigureAwait(false);
|
**Hosting Guides and docs can be found here**: <http://nadekobot.rtfd.io>").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Donate(IUserMessage umsg)
|
public async Task Donate(IUserMessage umsg)
|
||||||
{
|
{
|
||||||
|
@ -234,7 +234,7 @@ namespace NadekoBot.Modules.Music.Classes
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void ClearQueue()
|
public void ClearQueue()
|
||||||
{
|
{
|
||||||
actionQueue.Enqueue(() =>
|
actionQueue.Enqueue(() =>
|
||||||
{
|
{
|
||||||
@ -256,7 +256,7 @@ namespace NadekoBot.Modules.Music.Classes
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
internal Task MoveToVoiceChannel(IVoiceChannel voiceChannel)
|
public Task MoveToVoiceChannel(IVoiceChannel voiceChannel)
|
||||||
{
|
{
|
||||||
if (audioClient?.ConnectionState != ConnectionState.Connected)
|
if (audioClient?.ConnectionState != ConnectionState.Connected)
|
||||||
throw new InvalidOperationException("Can't move while bot is not connected to voice channel.");
|
throw new InvalidOperationException("Can't move while bot is not connected to voice channel.");
|
||||||
@ -264,13 +264,13 @@ namespace NadekoBot.Modules.Music.Classes
|
|||||||
return PlaybackVoiceChannel.ConnectAsync();
|
return PlaybackVoiceChannel.ConnectAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal bool ToggleRepeatSong() => this.RepeatSong = !this.RepeatSong;
|
public bool ToggleRepeatSong() => this.RepeatSong = !this.RepeatSong;
|
||||||
|
|
||||||
internal bool ToggleRepeatPlaylist() => this.RepeatPlaylist = !this.RepeatPlaylist;
|
public bool ToggleRepeatPlaylist() => this.RepeatPlaylist = !this.RepeatPlaylist;
|
||||||
|
|
||||||
internal bool ToggleAutoplay() => this.Autoplay = !this.Autoplay;
|
public bool ToggleAutoplay() => this.Autoplay = !this.Autoplay;
|
||||||
|
|
||||||
internal void ThrowIfQueueFull()
|
public void ThrowIfQueueFull()
|
||||||
{
|
{
|
||||||
if (MaxQueueSize == 0)
|
if (MaxQueueSize == 0)
|
||||||
return;
|
return;
|
||||||
|
@ -16,18 +16,18 @@ namespace NadekoBot.Modules.Music.Classes
|
|||||||
{
|
{
|
||||||
public class SongInfo
|
public class SongInfo
|
||||||
{
|
{
|
||||||
public string Provider { get; internal set; }
|
public string Provider { get; set; }
|
||||||
public MusicType ProviderType { get; internal set; }
|
public MusicType ProviderType { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Will be set only if the providertype is normal
|
/// Will be set only if the providertype is normal
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Query { get; internal set; }
|
public string Query { get; set; }
|
||||||
public string Title { get; internal set; }
|
public string Title { get; set; }
|
||||||
public string Uri { get; internal set; }
|
public string Uri { get; set; }
|
||||||
}
|
}
|
||||||
public class Song
|
public class Song
|
||||||
{
|
{
|
||||||
public StreamState State { get; internal set; }
|
public StreamState State { get; set; }
|
||||||
public string PrettyName =>
|
public string PrettyName =>
|
||||||
$"**【 {SongInfo.Title.TrimTo(55)} 】**`{(SongInfo.Provider ?? "-")}` `by {QueuerName}`";
|
$"**【 {SongInfo.Title.TrimTo(55)} 】**`{(SongInfo.Provider ?? "-")}` `by {QueuerName}`";
|
||||||
public SongInfo SongInfo { get; }
|
public SongInfo SongInfo { get; }
|
||||||
@ -80,11 +80,11 @@ namespace NadekoBot.Modules.Music.Classes
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task Play(IAudioClient voiceClient, CancellationToken cancelToken)
|
public async Task Play(IAudioClient voiceClient, CancellationToken cancelToken)
|
||||||
{
|
{
|
||||||
var filename = Path.Combine(Music.MusicDataPath, DateTime.Now.UnixTimestamp().ToString());
|
var filename = Path.Combine(Music.MusicDataPath, DateTime.Now.UnixTimestamp().ToString());
|
||||||
|
|
||||||
SongBuffer inStream = new SongBuffer(MusicPlayer, filename, SongInfo, skipTo);
|
SongBuffer inStream = new SongBuffer(MusicPlayer, filename, SongInfo, skipTo, frameBytes * 100);
|
||||||
var bufferTask = inStream.BufferSong(cancelToken).ConfigureAwait(false);
|
var bufferTask = inStream.BufferSong(cancelToken).ConfigureAwait(false);
|
||||||
|
|
||||||
bytesSent = 0;
|
bytesSent = 0;
|
||||||
@ -118,8 +118,9 @@ namespace NadekoBot.Modules.Music.Classes
|
|||||||
while (!cancelToken.IsCancellationRequested)
|
while (!cancelToken.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
//Console.WriteLine($"Read: {songBuffer.ReadPosition}\nWrite: {songBuffer.WritePosition}\nContentLength:{songBuffer.ContentLength}\n---------");
|
//Console.WriteLine($"Read: {songBuffer.ReadPosition}\nWrite: {songBuffer.WritePosition}\nContentLength:{songBuffer.ContentLength}\n---------");
|
||||||
var read = inStream.Read(buffer, 0, buffer.Length);
|
var read = await inStream.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false);
|
||||||
//await inStream.CopyToAsync(voiceClient.OutputStream);
|
//await inStream.CopyToAsync(voiceClient.OutputStream);
|
||||||
|
if(read < frameBytes)
|
||||||
_log.Debug("read {0}", read);
|
_log.Debug("read {0}", read);
|
||||||
unchecked
|
unchecked
|
||||||
{
|
{
|
||||||
@ -155,7 +156,7 @@ namespace NadekoBot.Modules.Music.Classes
|
|||||||
int delayMillis = unchecked(nextTime - Environment.TickCount);
|
int delayMillis = unchecked(nextTime - Environment.TickCount);
|
||||||
if (delayMillis > 0)
|
if (delayMillis > 0)
|
||||||
await Task.Delay(delayMillis, cancelToken).ConfigureAwait(false);
|
await Task.Delay(delayMillis, cancelToken).ConfigureAwait(false);
|
||||||
await outStream.WriteAsync(buffer, 0, read);
|
await outStream.WriteAsync(buffer, 0, read).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using NadekoBot.Extensions;
|
using NadekoBot.Extensions;
|
||||||
|
using NLog;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -17,14 +18,15 @@ namespace NadekoBot.Modules.Music.Classes
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
class SongBuffer : Stream
|
class SongBuffer : Stream
|
||||||
{
|
{
|
||||||
|
public SongBuffer(MusicPlayer musicPlayer, string basename, SongInfo songInfo, int skipTo, int maxFileSize)
|
||||||
public SongBuffer(MusicPlayer musicPlayer, string basename, SongInfo songInfo, int skipTo)
|
|
||||||
{
|
{
|
||||||
MusicPlayer = musicPlayer;
|
MusicPlayer = musicPlayer;
|
||||||
Basename = basename;
|
Basename = basename;
|
||||||
SongInfo = songInfo;
|
SongInfo = songInfo;
|
||||||
SkipTo = skipTo;
|
SkipTo = skipTo;
|
||||||
|
MaxFileSize = maxFileSize;
|
||||||
CurrentFileStream = new FileStream(this.GetNextFile(), FileMode.OpenOrCreate, FileAccess.Read, FileShare.Write);
|
CurrentFileStream = new FileStream(this.GetNextFile(), FileMode.OpenOrCreate, FileAccess.Read, FileShare.Write);
|
||||||
|
_log = LogManager.GetCurrentClassLogger();
|
||||||
}
|
}
|
||||||
|
|
||||||
MusicPlayer MusicPlayer;
|
MusicPlayer MusicPlayer;
|
||||||
@ -35,7 +37,7 @@ namespace NadekoBot.Modules.Music.Classes
|
|||||||
|
|
||||||
private int SkipTo;
|
private int SkipTo;
|
||||||
|
|
||||||
private static int MAX_FILE_SIZE = 2.MiB();
|
private int MaxFileSize = 2.MiB();
|
||||||
|
|
||||||
private long FileNumber = -1;
|
private long FileNumber = -1;
|
||||||
|
|
||||||
@ -46,9 +48,10 @@ namespace NadekoBot.Modules.Music.Classes
|
|||||||
private ulong CurrentBufferSize = 0;
|
private ulong CurrentBufferSize = 0;
|
||||||
|
|
||||||
private FileStream CurrentFileStream;
|
private FileStream CurrentFileStream;
|
||||||
|
private Logger _log;
|
||||||
|
|
||||||
public Task BufferSong(CancellationToken cancelToken) =>
|
public Task BufferSong(CancellationToken cancelToken) =>
|
||||||
Task.Factory.StartNew(async () =>
|
Task.Run(async () =>
|
||||||
{
|
{
|
||||||
Process p = null;
|
Process p = null;
|
||||||
FileStream outStream = null;
|
FileStream outStream = null;
|
||||||
@ -72,7 +75,7 @@ namespace NadekoBot.Modules.Music.Classes
|
|||||||
while (!p.HasExited) //Also fix low bandwidth
|
while (!p.HasExited) //Also fix low bandwidth
|
||||||
{
|
{
|
||||||
int bytesRead = await p.StandardOutput.BaseStream.ReadAsync(buffer, 0, buffer.Length, cancelToken).ConfigureAwait(false);
|
int bytesRead = await p.StandardOutput.BaseStream.ReadAsync(buffer, 0, buffer.Length, cancelToken).ConfigureAwait(false);
|
||||||
if (currentFileSize >= MAX_FILE_SIZE)
|
if (currentFileSize >= MaxFileSize)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -122,7 +125,7 @@ Check the guides for your platform on how to setup ffmpeg correctly:
|
|||||||
p.Dispose();
|
p.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, TaskCreationOptions.LongRunning);
|
});
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Return the next file to read, and delete the old one
|
/// Return the next file to read, and delete the old one
|
||||||
@ -172,18 +175,7 @@ Check the guides for your platform on how to setup ffmpeg correctly:
|
|||||||
|
|
||||||
public override long Length => (long) CurrentBufferSize;
|
public override long Length => (long) CurrentBufferSize;
|
||||||
|
|
||||||
public override long Position
|
public override long Position { get; set; } = 0;
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
set
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Flush() { }
|
public override void Flush() { }
|
||||||
|
|
||||||
@ -198,6 +190,8 @@ Check the guides for your platform on how to setup ffmpeg correctly:
|
|||||||
CurrentFileStream = new FileStream(GetNextFile(), FileMode.OpenOrCreate, FileAccess.Read, FileShare.Write);
|
CurrentFileStream = new FileStream(GetNextFile(), FileMode.OpenOrCreate, FileAccess.Read, FileShare.Write);
|
||||||
read += CurrentFileStream.Read(buffer, read + offset, count - read);
|
read += CurrentFileStream.Read(buffer, read + offset, count - read);
|
||||||
}
|
}
|
||||||
|
if (read < count)
|
||||||
|
Array.Clear(buffer, read, count - read);
|
||||||
}
|
}
|
||||||
return read;
|
return read;
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ namespace NadekoBot.Modules.Music.Classes
|
|||||||
public bool IsSoundCloudLink(string url) =>
|
public bool IsSoundCloudLink(string url) =>
|
||||||
System.Text.RegularExpressions.Regex.IsMatch(url, "(.*)(soundcloud.com|snd.sc)(.*)");
|
System.Text.RegularExpressions.Regex.IsMatch(url, "(.*)(soundcloud.com|snd.sc)(.*)");
|
||||||
|
|
||||||
internal async Task<SoundCloudVideo> GetVideoByQueryAsync(string query)
|
public async Task<SoundCloudVideo> GetVideoByQueryAsync(string query)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(query))
|
if (string.IsNullOrWhiteSpace(query))
|
||||||
throw new ArgumentNullException(nameof(query));
|
throw new ArgumentNullException(nameof(query));
|
||||||
|
@ -13,10 +13,11 @@ using NadekoBot.Extensions;
|
|||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using NadekoBot.Services.Database;
|
||||||
|
|
||||||
namespace NadekoBot.Modules.Music
|
namespace NadekoBot.Modules.Music
|
||||||
{
|
{
|
||||||
[Module("!!", AppendSpace = false)]
|
[NadekoModule("ClashOfClans", "!!")]
|
||||||
public partial class Music : DiscordModule
|
public partial class Music : DiscordModule
|
||||||
{
|
{
|
||||||
public static ConcurrentDictionary<ulong, MusicPlayer> MusicPlayers = new ConcurrentDictionary<ulong, MusicPlayer>();
|
public static ConcurrentDictionary<ulong, MusicPlayer> MusicPlayers = new ConcurrentDictionary<ulong, MusicPlayer>();
|
||||||
@ -34,46 +35,49 @@ namespace NadekoBot.Modules.Music
|
|||||||
_google = google;
|
_google = google;
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Next(IUserMessage umsg)
|
public Task Next(IUserMessage umsg)
|
||||||
{
|
{
|
||||||
var channel = (ITextChannel)umsg.Channel;
|
var channel = (ITextChannel)umsg.Channel;
|
||||||
|
|
||||||
MusicPlayer musicPlayer;
|
MusicPlayer musicPlayer;
|
||||||
if (!MusicPlayers.TryGetValue(channel.Guild.Id, out musicPlayer)) return;
|
if (!MusicPlayers.TryGetValue(channel.Guild.Id, out musicPlayer)) return Task.CompletedTask;
|
||||||
if (musicPlayer.PlaybackVoiceChannel == ((IGuildUser)umsg.Author).VoiceChannel)
|
if (musicPlayer.PlaybackVoiceChannel == ((IGuildUser)umsg.Author).VoiceChannel)
|
||||||
musicPlayer.Next();
|
musicPlayer.Next();
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Stop(IUserMessage umsg)
|
public Task Stop(IUserMessage umsg)
|
||||||
{
|
{
|
||||||
var channel = (ITextChannel)umsg.Channel;
|
var channel = (ITextChannel)umsg.Channel;
|
||||||
|
|
||||||
MusicPlayer musicPlayer;
|
MusicPlayer musicPlayer;
|
||||||
if (!MusicPlayers.TryGetValue(channel.Guild.Id, out musicPlayer)) return;
|
if (!MusicPlayers.TryGetValue(channel.Guild.Id, out musicPlayer)) return Task.CompletedTask;
|
||||||
if (((IGuildUser)umsg.Author).VoiceChannel == musicPlayer.PlaybackVoiceChannel)
|
if (((IGuildUser)umsg.Author).VoiceChannel == musicPlayer.PlaybackVoiceChannel)
|
||||||
{
|
{
|
||||||
musicPlayer.Autoplay = false;
|
musicPlayer.Autoplay = false;
|
||||||
musicPlayer.Stop();
|
musicPlayer.Stop();
|
||||||
}
|
}
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Destroy(IUserMessage umsg)
|
public Task Destroy(IUserMessage umsg)
|
||||||
{
|
{
|
||||||
var channel = (ITextChannel)umsg.Channel;
|
var channel = (ITextChannel)umsg.Channel;
|
||||||
|
|
||||||
MusicPlayer musicPlayer;
|
MusicPlayer musicPlayer;
|
||||||
if (!MusicPlayers.TryRemove(channel.Guild.Id, out musicPlayer)) return;
|
if (!MusicPlayers.TryRemove(channel.Guild.Id, out musicPlayer)) return Task.CompletedTask;
|
||||||
if (((IGuildUser)umsg.Author).VoiceChannel == musicPlayer.PlaybackVoiceChannel)
|
if (((IGuildUser)umsg.Author).VoiceChannel == musicPlayer.PlaybackVoiceChannel)
|
||||||
musicPlayer.Destroy();
|
musicPlayer.Destroy();
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Pause(IUserMessage umsg)
|
public async Task Pause(IUserMessage umsg)
|
||||||
{
|
{
|
||||||
@ -90,7 +94,7 @@ namespace NadekoBot.Modules.Music
|
|||||||
await channel.SendMessageAsync("🎵`Music Player unpaused.`").ConfigureAwait(false);
|
await channel.SendMessageAsync("🎵`Music Player unpaused.`").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Queue(IUserMessage umsg, [Remainder] string query)
|
public async Task Queue(IUserMessage umsg, [Remainder] string query)
|
||||||
{
|
{
|
||||||
@ -104,7 +108,7 @@ namespace NadekoBot.Modules.Music
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task SoundCloudQueue(IUserMessage umsg, [Remainder] string query)
|
public async Task SoundCloudQueue(IUserMessage umsg, [Remainder] string query)
|
||||||
{
|
{
|
||||||
@ -118,7 +122,7 @@ namespace NadekoBot.Modules.Music
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task ListQueue(IUserMessage umsg, int page = 1)
|
public async Task ListQueue(IUserMessage umsg, int page = 1)
|
||||||
{
|
{
|
||||||
@ -151,7 +155,7 @@ namespace NadekoBot.Modules.Music
|
|||||||
await channel.SendMessageAsync(toSend + string.Join("\n", musicPlayer.Playlist.Skip(startAt).Take(15).Select(v => $"`{number++}.` {v.PrettyName}"))).ConfigureAwait(false);
|
await channel.SendMessageAsync(toSend + string.Join("\n", musicPlayer.Playlist.Skip(startAt).Take(15).Select(v => $"`{number++}.` {v.PrettyName}"))).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task NowPlaying(IUserMessage umsg)
|
public async Task NowPlaying(IUserMessage umsg)
|
||||||
{
|
{
|
||||||
@ -166,7 +170,7 @@ namespace NadekoBot.Modules.Music
|
|||||||
$"{currentSong.PrettyCurrentTime()}").ConfigureAwait(false);
|
$"{currentSong.PrettyCurrentTime()}").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Volume(IUserMessage umsg, int val)
|
public async Task Volume(IUserMessage umsg, int val)
|
||||||
{
|
{
|
||||||
@ -181,51 +185,55 @@ namespace NadekoBot.Modules.Music
|
|||||||
var volume = musicPlayer.SetVolume(val);
|
var volume = musicPlayer.SetVolume(val);
|
||||||
await channel.SendMessageAsync($"🎵 `Volume set to {volume}%`").ConfigureAwait(false);
|
await channel.SendMessageAsync($"🎵 `Volume set to {volume}%`").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
////todo DB
|
|
||||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
|
||||||
//[RequireContext(ContextType.Guild)]
|
|
||||||
//public async Task Defvol(IUserMessage umsg, [Remainder] int val)
|
|
||||||
//{
|
|
||||||
// var channel = (ITextChannel)umsg.Channel;
|
|
||||||
// var arg = val;
|
|
||||||
// float volume;
|
|
||||||
// if (!float.TryParse(arg, out volume) || volume < 0 || volume > 100)
|
|
||||||
// {
|
|
||||||
// await channel.SendMessageAsync("Volume number invalid.").ConfigureAwait(false);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// var conf = SpecificConfigurations.Default.Of(channel.Guild.Id);
|
|
||||||
// conf.DefaultMusicVolume = volume / 100;
|
|
||||||
// await channel.SendMessageAsync($"🎵 `Default volume set to {volume}%`").ConfigureAwait(false);
|
|
||||||
//}
|
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Mute(IUserMessage umsg)
|
public async Task Defvol(IUserMessage umsg, [Remainder] int val)
|
||||||
|
{
|
||||||
|
var channel = (ITextChannel)umsg.Channel;
|
||||||
|
|
||||||
|
if (val < 0 || val > 100)
|
||||||
|
{
|
||||||
|
await channel.SendMessageAsync("Volume number invalid. Must be between 0 and 100").ConfigureAwait(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
|
{
|
||||||
|
uow.GuildConfigs.For(channel.Guild.Id).DefaultMusicVolume = val / 100.0f;
|
||||||
|
uow.Complete();
|
||||||
|
}
|
||||||
|
await channel.SendMessageAsync($"🎵 `Default volume set to {val}%`").ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
|
[RequireContext(ContextType.Guild)]
|
||||||
|
public Task Mute(IUserMessage umsg)
|
||||||
{
|
{
|
||||||
var channel = (ITextChannel)umsg.Channel;
|
var channel = (ITextChannel)umsg.Channel;
|
||||||
MusicPlayer musicPlayer;
|
MusicPlayer musicPlayer;
|
||||||
if (!MusicPlayers.TryGetValue(channel.Guild.Id, out musicPlayer))
|
if (!MusicPlayers.TryGetValue(channel.Guild.Id, out musicPlayer))
|
||||||
return;
|
return Task.CompletedTask;
|
||||||
if (((IGuildUser)umsg.Author).VoiceChannel != musicPlayer.PlaybackVoiceChannel)
|
if (((IGuildUser)umsg.Author).VoiceChannel != musicPlayer.PlaybackVoiceChannel)
|
||||||
return;
|
return Task.CompletedTask;
|
||||||
musicPlayer.SetVolume(0);
|
musicPlayer.SetVolume(0);
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Max(IUserMessage umsg)
|
public Task Max(IUserMessage umsg)
|
||||||
{
|
{
|
||||||
var channel = (ITextChannel)umsg.Channel;
|
var channel = (ITextChannel)umsg.Channel;
|
||||||
MusicPlayer musicPlayer;
|
MusicPlayer musicPlayer;
|
||||||
if (!MusicPlayers.TryGetValue(channel.Guild.Id, out musicPlayer))
|
if (!MusicPlayers.TryGetValue(channel.Guild.Id, out musicPlayer))
|
||||||
return;
|
return Task.CompletedTask;
|
||||||
if (((IGuildUser)umsg.Author).VoiceChannel != musicPlayer.PlaybackVoiceChannel)
|
if (((IGuildUser)umsg.Author).VoiceChannel != musicPlayer.PlaybackVoiceChannel)
|
||||||
return;
|
return Task.CompletedTask;
|
||||||
musicPlayer.SetVolume(100);
|
musicPlayer.SetVolume(100);
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Shuffle(IUserMessage umsg)
|
public async Task Shuffle(IUserMessage umsg)
|
||||||
{
|
{
|
||||||
@ -245,7 +253,7 @@ namespace NadekoBot.Modules.Music
|
|||||||
await channel.SendMessageAsync("🎵 `Songs shuffled.`").ConfigureAwait(false);
|
await channel.SendMessageAsync("🎵 `Songs shuffled.`").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Playlist(IUserMessage umsg, [Remainder] string playlist)
|
public async Task Playlist(IUserMessage umsg, [Remainder] string playlist)
|
||||||
{
|
{
|
||||||
@ -287,7 +295,7 @@ namespace NadekoBot.Modules.Music
|
|||||||
await msg.ModifyAsync(m => m.Content = "🎵 `Playlist queue complete.`").ConfigureAwait(false);
|
await msg.ModifyAsync(m => m.Content = "🎵 `Playlist queue complete.`").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task SoundCloudPl(IUserMessage umsg, [Remainder] string pl)
|
public async Task SoundCloudPl(IUserMessage umsg, [Remainder] string pl)
|
||||||
{
|
{
|
||||||
@ -324,7 +332,7 @@ namespace NadekoBot.Modules.Music
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task LocalPl(IUserMessage umsg, [Remainder] string directory)
|
public async Task LocalPl(IUserMessage umsg, [Remainder] string directory)
|
||||||
{
|
{
|
||||||
@ -353,7 +361,7 @@ namespace NadekoBot.Modules.Music
|
|||||||
catch { }
|
catch { }
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Radio(IUserMessage umsg, string radio_link)
|
public async Task Radio(IUserMessage umsg, string radio_link)
|
||||||
{
|
{
|
||||||
@ -371,7 +379,7 @@ namespace NadekoBot.Modules.Music
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Local(IUserMessage umsg, [Remainder] string path)
|
public async Task Local(IUserMessage umsg, [Remainder] string path)
|
||||||
{
|
{
|
||||||
@ -383,7 +391,7 @@ namespace NadekoBot.Modules.Music
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Move(IUserMessage umsg)
|
public async Task Move(IUserMessage umsg)
|
||||||
{
|
{
|
||||||
@ -392,10 +400,10 @@ namespace NadekoBot.Modules.Music
|
|||||||
var voiceChannel = ((IGuildUser)umsg.Author).VoiceChannel;
|
var voiceChannel = ((IGuildUser)umsg.Author).VoiceChannel;
|
||||||
if (voiceChannel == null || voiceChannel.Guild != channel.Guild || !MusicPlayers.TryGetValue(channel.Guild.Id, out musicPlayer))
|
if (voiceChannel == null || voiceChannel.Guild != channel.Guild || !MusicPlayers.TryGetValue(channel.Guild.Id, out musicPlayer))
|
||||||
return;
|
return;
|
||||||
musicPlayer.MoveToVoiceChannel(voiceChannel);
|
await musicPlayer.MoveToVoiceChannel(voiceChannel);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Remove(IUserMessage umsg, int num)
|
public async Task Remove(IUserMessage umsg, int num)
|
||||||
{
|
{
|
||||||
@ -414,8 +422,8 @@ namespace NadekoBot.Modules.Music
|
|||||||
musicPlayer.RemoveSongAt(num - 1);
|
musicPlayer.RemoveSongAt(num - 1);
|
||||||
await channel.SendMessageAsync($"🎵**Track {song.PrettyName} at position `#{num}` has been removed.**").ConfigureAwait(false);
|
await channel.SendMessageAsync($"🎵**Track {song.PrettyName} at position `#{num}` has been removed.**").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
//todo fix
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Remove(IUserMessage umsg, string all)
|
public async Task Remove(IUserMessage umsg, string all)
|
||||||
{
|
{
|
||||||
@ -430,7 +438,7 @@ namespace NadekoBot.Modules.Music
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task MoveSong(IUserMessage umsg, [Remainder] string fromto)
|
public async Task MoveSong(IUserMessage umsg, [Remainder] string fromto)
|
||||||
{
|
{
|
||||||
@ -466,7 +474,7 @@ namespace NadekoBot.Modules.Music
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task SetMaxQueue(IUserMessage umsg, uint size)
|
public async Task SetMaxQueue(IUserMessage umsg, uint size)
|
||||||
{
|
{
|
||||||
@ -480,7 +488,7 @@ namespace NadekoBot.Modules.Music
|
|||||||
await channel.SendMessageAsync($"🎵 `Max queue set to {(size == 0 ? ("unlimited") : size + " tracks")}`");
|
await channel.SendMessageAsync($"🎵 `Max queue set to {(size == 0 ? ("unlimited") : size + " tracks")}`");
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task ReptCurSong(IUserMessage umsg)
|
public async Task ReptCurSong(IUserMessage umsg)
|
||||||
{
|
{
|
||||||
@ -498,7 +506,7 @@ namespace NadekoBot.Modules.Music
|
|||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task RepeatPl(IUserMessage umsg)
|
public async Task RepeatPl(IUserMessage umsg)
|
||||||
{
|
{
|
||||||
@ -511,7 +519,7 @@ namespace NadekoBot.Modules.Music
|
|||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
//[RequireContext(ContextType.Guild)]
|
//[RequireContext(ContextType.Guild)]
|
||||||
//public async Task Save(IUserMessage umsg, [Remainder] string name)
|
//public async Task Save(IUserMessage umsg, [Remainder] string name)
|
||||||
//{
|
//{
|
||||||
@ -519,7 +527,7 @@ namespace NadekoBot.Modules.Music
|
|||||||
|
|
||||||
//}
|
//}
|
||||||
|
|
||||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
//[RequireContext(ContextType.Guild)]
|
//[RequireContext(ContextType.Guild)]
|
||||||
//public async Task Load(IUserMessage umsg, [Remainder] string name)
|
//public async Task Load(IUserMessage umsg, [Remainder] string name)
|
||||||
//{
|
//{
|
||||||
@ -527,7 +535,7 @@ namespace NadekoBot.Modules.Music
|
|||||||
|
|
||||||
//}
|
//}
|
||||||
|
|
||||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
//[RequireContext(ContextType.Guild)]
|
//[RequireContext(ContextType.Guild)]
|
||||||
//public async Task Playlists(IUserMessage umsg, [Remainder] string num)
|
//public async Task Playlists(IUserMessage umsg, [Remainder] string num)
|
||||||
//{
|
//{
|
||||||
@ -535,7 +543,7 @@ namespace NadekoBot.Modules.Music
|
|||||||
|
|
||||||
//}
|
//}
|
||||||
|
|
||||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
//[RequireContext(ContextType.Guild)]
|
//[RequireContext(ContextType.Guild)]
|
||||||
//public async Task DeletePlaylist(IUserMessage umsg, [Remainder] string pl)
|
//public async Task DeletePlaylist(IUserMessage umsg, [Remainder] string pl)
|
||||||
//{
|
//{
|
||||||
@ -543,7 +551,7 @@ namespace NadekoBot.Modules.Music
|
|||||||
|
|
||||||
//}
|
//}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Goto(IUserMessage umsg, int time)
|
public async Task Goto(IUserMessage umsg, int time)
|
||||||
{
|
{
|
||||||
@ -580,7 +588,7 @@ namespace NadekoBot.Modules.Music
|
|||||||
await channel.SendMessageAsync($"`Skipped to {minutes}:{seconds}`").ConfigureAwait(false);
|
await channel.SendMessageAsync($"`Skipped to {minutes}:{seconds}`").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task GetLink(IUserMessage umsg, int index = 0)
|
public async Task GetLink(IUserMessage umsg, int index = 0)
|
||||||
{
|
{
|
||||||
@ -615,7 +623,7 @@ namespace NadekoBot.Modules.Music
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Autoplay(IUserMessage umsg)
|
public async Task Autoplay(IUserMessage umsg)
|
||||||
{
|
{
|
||||||
@ -643,8 +651,11 @@ namespace NadekoBot.Modules.Music
|
|||||||
|
|
||||||
var musicPlayer = MusicPlayers.GetOrAdd(textCh.Guild.Id, server =>
|
var musicPlayer = MusicPlayers.GetOrAdd(textCh.Guild.Id, server =>
|
||||||
{
|
{
|
||||||
//todo DB
|
|
||||||
float vol = 1;// SpecificConfigurations.Default.Of(server.Id).DefaultMusicVolume;
|
float vol = 1;// SpecificConfigurations.Default.Of(server.Id).DefaultMusicVolume;
|
||||||
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
|
{
|
||||||
|
vol = uow.GuildConfigs.For(textCh.Guild.Id).DefaultMusicVolume;
|
||||||
|
}
|
||||||
var mp = new MusicPlayer(voiceCh, vol);
|
var mp = new MusicPlayer(voiceCh, vol);
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,14 +15,14 @@ using NadekoBot.Extensions;
|
|||||||
|
|
||||||
namespace NadekoBot.Modules.NSFW
|
namespace NadekoBot.Modules.NSFW
|
||||||
{
|
{
|
||||||
[Module("~", AppendSpace = false)]
|
[NadekoModule("NSFW", "~")]
|
||||||
public class NSFW : DiscordModule
|
public class NSFW : DiscordModule
|
||||||
{
|
{
|
||||||
public NSFW(ILocalization loc, CommandService cmds, DiscordSocketClient client) : base(loc, cmds, client)
|
public NSFW(ILocalization loc, CommandService cmds, DiscordSocketClient client) : base(loc, cmds, client)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Hentai(IUserMessage umsg, [Remainder] string tag = null)
|
public async Task Hentai(IUserMessage umsg, [Remainder] string tag = null)
|
||||||
{
|
{
|
||||||
@ -41,7 +41,7 @@ namespace NadekoBot.Modules.NSFW
|
|||||||
await channel.SendMessageAsync(String.Join("\n\n", links)).ConfigureAwait(false);
|
await channel.SendMessageAsync(String.Join("\n\n", links)).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Danbooru(IUserMessage umsg, [Remainder] string tag = null)
|
public async Task Danbooru(IUserMessage umsg, [Remainder] string tag = null)
|
||||||
{
|
{
|
||||||
@ -55,7 +55,7 @@ namespace NadekoBot.Modules.NSFW
|
|||||||
await channel.SendMessageAsync(link).ConfigureAwait(false);
|
await channel.SendMessageAsync(link).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Gelbooru(IUserMessage umsg, [Remainder] string tag = null)
|
public async Task Gelbooru(IUserMessage umsg, [Remainder] string tag = null)
|
||||||
{
|
{
|
||||||
@ -69,7 +69,7 @@ namespace NadekoBot.Modules.NSFW
|
|||||||
await channel.SendMessageAsync(link).ConfigureAwait(false);
|
await channel.SendMessageAsync(link).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Rule34(IUserMessage umsg, [Remainder] string tag = null)
|
public async Task Rule34(IUserMessage umsg, [Remainder] string tag = null)
|
||||||
{
|
{
|
||||||
@ -83,7 +83,7 @@ namespace NadekoBot.Modules.NSFW
|
|||||||
await channel.SendMessageAsync(link).ConfigureAwait(false);
|
await channel.SendMessageAsync(link).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task E621(IUserMessage umsg, [Remainder] string tag = null)
|
public async Task E621(IUserMessage umsg, [Remainder] string tag = null)
|
||||||
{
|
{
|
||||||
@ -97,7 +97,7 @@ namespace NadekoBot.Modules.NSFW
|
|||||||
await channel.SendMessageAsync(link).ConfigureAwait(false);
|
await channel.SendMessageAsync(link).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Cp(IUserMessage umsg)
|
public async Task Cp(IUserMessage umsg)
|
||||||
{
|
{
|
||||||
@ -106,7 +106,7 @@ namespace NadekoBot.Modules.NSFW
|
|||||||
await channel.SendMessageAsync("http://i.imgur.com/MZkY1md.jpg").ConfigureAwait(false);
|
await channel.SendMessageAsync("http://i.imgur.com/MZkY1md.jpg").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Boobs(IUserMessage umsg)
|
public async Task Boobs(IUserMessage umsg)
|
||||||
{
|
{
|
||||||
@ -116,7 +116,7 @@ namespace NadekoBot.Modules.NSFW
|
|||||||
JToken obj;
|
JToken obj;
|
||||||
using (var http = new HttpClient())
|
using (var http = new HttpClient())
|
||||||
{
|
{
|
||||||
obj = JArray.Parse(await http.GetStringAsync($"http://api.oboobs.ru/boobs/{ new Random().Next(0, 9880) }").ConfigureAwait(false))[0];
|
obj = JArray.Parse(await http.GetStringAsync($"http://api.oboobs.ru/boobs/{ new NadekoRandom().Next(0, 9880) }").ConfigureAwait(false))[0];
|
||||||
}
|
}
|
||||||
await channel.SendMessageAsync($"http://media.oboobs.ru/{ obj["preview"].ToString() }").ConfigureAwait(false);
|
await channel.SendMessageAsync($"http://media.oboobs.ru/{ obj["preview"].ToString() }").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
@ -126,7 +126,7 @@ namespace NadekoBot.Modules.NSFW
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Butts(IUserMessage umsg)
|
public async Task Butts(IUserMessage umsg)
|
||||||
{
|
{
|
||||||
@ -137,7 +137,7 @@ namespace NadekoBot.Modules.NSFW
|
|||||||
JToken obj;
|
JToken obj;
|
||||||
using (var http = new HttpClient())
|
using (var http = new HttpClient())
|
||||||
{
|
{
|
||||||
obj = JArray.Parse(await http.GetStringAsync($"http://api.obutts.ru/butts/{ new Random().Next(0, 3873) }").ConfigureAwait(false))[0];
|
obj = JArray.Parse(await http.GetStringAsync($"http://api.obutts.ru/butts/{ new NadekoRandom().Next(0, 3873) }").ConfigureAwait(false))[0];
|
||||||
}
|
}
|
||||||
await channel.SendMessageAsync($"http://media.obutts.ru/{ obj["preview"].ToString() }").ConfigureAwait(false);
|
await channel.SendMessageAsync($"http://media.obutts.ru/{ obj["preview"].ToString() }").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
@ -149,7 +149,7 @@ namespace NadekoBot.Modules.NSFW
|
|||||||
|
|
||||||
public static async Task<string> GetDanbooruImageLink(string tag)
|
public static async Task<string> GetDanbooruImageLink(string tag)
|
||||||
{
|
{
|
||||||
var rng = new Random();
|
var rng = new NadekoRandom();
|
||||||
|
|
||||||
if (tag == "loli") //loli doesn't work for some reason atm
|
if (tag == "loli") //loli doesn't work for some reason atm
|
||||||
tag = "flat_chest";
|
tag = "flat_chest";
|
||||||
@ -181,7 +181,7 @@ namespace NadekoBot.Modules.NSFW
|
|||||||
if (matches.Count == 0)
|
if (matches.Count == 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
var rng = new Random();
|
var rng = new NadekoRandom();
|
||||||
var match = matches[rng.Next(0, matches.Count)];
|
var match = matches[rng.Next(0, matches.Count)];
|
||||||
return matches[rng.Next(0, matches.Count)].Groups["url"].Value;
|
return matches[rng.Next(0, matches.Count)].Groups["url"].Value;
|
||||||
}
|
}
|
||||||
@ -189,7 +189,7 @@ namespace NadekoBot.Modules.NSFW
|
|||||||
|
|
||||||
public static async Task<string> GetRule34ImageLink(string tag)
|
public static async Task<string> GetRule34ImageLink(string tag)
|
||||||
{
|
{
|
||||||
var rng = new Random();
|
var rng = new NadekoRandom();
|
||||||
var url =
|
var url =
|
||||||
$"http://rule34.xxx/index.php?page=dapi&s=post&q=index&limit=100&tags={tag.Replace(" ", "_")}";
|
$"http://rule34.xxx/index.php?page=dapi&s=post&q=index&limit=100&tags={tag.Replace(" ", "_")}";
|
||||||
using (var http = new HttpClient())
|
using (var http = new HttpClient())
|
||||||
@ -204,7 +204,7 @@ namespace NadekoBot.Modules.NSFW
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
internal static async Task<string> GetE621ImageLink(string tags)
|
public static async Task<string> GetE621ImageLink(string tags)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -15,7 +15,7 @@ namespace NadekoBot.Modules.Games
|
|||||||
}
|
}
|
||||||
|
|
||||||
//todo Dragon should PR this in
|
//todo Dragon should PR this in
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Poke(IUserMessage umsg)
|
public async Task Poke(IUserMessage umsg)
|
||||||
{
|
{
|
||||||
|
@ -1,99 +1,132 @@
|
|||||||
//using Discord;
|
using Discord;
|
||||||
//using Discord.Commands;
|
using Discord.Commands;
|
||||||
//using NadekoBot.Attributes;
|
using NadekoBot.Attributes;
|
||||||
//using System;
|
using NadekoBot.Extensions;
|
||||||
//using System.Collections.Generic;
|
using NadekoBot.Modules.Searches.Models;
|
||||||
//using System.Linq;
|
using Newtonsoft.Json;
|
||||||
//using System.Threading.Tasks;
|
using Newtonsoft.Json.Linq;
|
||||||
|
using NLog;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
//// todo RestSharp
|
namespace NadekoBot.Modules.Searches
|
||||||
//namespace NadekoBot.Modules.Searches
|
{
|
||||||
//{
|
public partial class Searches
|
||||||
// public partial class SearchesModule
|
{
|
||||||
// {
|
[Group]
|
||||||
// [LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
public class AnimeSearchCommands
|
||||||
// [RequireContext(ContextType.Guild)]
|
{
|
||||||
// public async Task Anime(IUserMessage umsg, [Remainder] string query = null)
|
private Logger _log;
|
||||||
// {
|
|
||||||
// var channel = (ITextChannel)umsg.Channel;
|
|
||||||
|
|
||||||
// if (!(await ValidateQuery(umsg.Channel as ITextChannel, query).ConfigureAwait(false))) return;
|
private string anilistToken { get; set; }
|
||||||
// string result;
|
private DateTime lastRefresh { get; set; }
|
||||||
// try
|
|
||||||
// {
|
|
||||||
// result = (await GetAnimeData(query).ConfigureAwait(false)).ToString();
|
|
||||||
// }
|
|
||||||
// catch
|
|
||||||
// {
|
|
||||||
// await channel.SendMessageAsync("Failed to find that anime.").ConfigureAwait(false);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// await channel.SendMessageAsync(result.ToString()).ConfigureAwait(false);
|
public AnimeSearchCommands()
|
||||||
// }
|
{
|
||||||
|
_log = LogManager.GetCurrentClassLogger();
|
||||||
|
}
|
||||||
|
|
||||||
// [LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
// [RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
// public async Task Manga(IUserMessage umsg, [Remainder] string query = null)
|
public async Task Anime(IUserMessage umsg, [Remainder] string query)
|
||||||
// {
|
{
|
||||||
// var channel = (ITextChannel)umsg.Channel;
|
var channel = (ITextChannel)umsg.Channel;
|
||||||
|
|
||||||
// if (!(await ValidateQuery(umsg.Channel as ITextChannel, query).ConfigureAwait(false))) return;
|
if (string.IsNullOrWhiteSpace(query))
|
||||||
// string result;
|
return;
|
||||||
// try
|
|
||||||
// {
|
|
||||||
// result = (await GetMangaData(query).ConfigureAwait(false)).ToString();
|
|
||||||
// }
|
|
||||||
// catch
|
|
||||||
// {
|
|
||||||
// await channel.SendMessageAsync("Failed to find that manga.").ConfigureAwait(false);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// await channel.SendMessageAsync(result).ConfigureAwait(false);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public static async Task<AnimeResult> GetAnimeData(string query)
|
var result = await GetAnimeData(query).ConfigureAwait(false);
|
||||||
// {
|
|
||||||
// if (string.IsNullOrWhiteSpace(query))
|
|
||||||
// throw new ArgumentNullException(nameof(query));
|
|
||||||
|
|
||||||
// await RefreshAnilistToken().ConfigureAwait(false);
|
await channel.SendMessageAsync(result.ToString() ?? "`No anime found.`").ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
// var link = "http://anilist.co/api/anime/search/" + Uri.EscapeUriString(query);
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
// var smallContent = "";
|
[RequireContext(ContextType.Guild)]
|
||||||
// var cl = new RestSharp.RestClient("http://anilist.co/api");
|
public async Task Manga(IUserMessage umsg, [Remainder] string query)
|
||||||
// var rq = new RestSharp.RestRequest("/anime/search/" + Uri.EscapeUriString(query));
|
{
|
||||||
// rq.AddParameter("access_token", token);
|
var channel = (ITextChannel)umsg.Channel;
|
||||||
// smallContent = cl.Execute(rq).Content;
|
|
||||||
// var smallObj = JArray.Parse(smallContent)[0];
|
|
||||||
|
|
||||||
// rq = new RestSharp.RestRequest("/anime/" + smallObj["id"]);
|
if (string.IsNullOrWhiteSpace(query))
|
||||||
// rq.AddParameter("access_token", token);
|
return;
|
||||||
// var content = cl.Execute(rq).Content;
|
|
||||||
|
|
||||||
// return await Task.Run(() => JsonConvert.DeserializeObject<AnimeResult>(content)).ConfigureAwait(false);
|
var result = await GetMangaData(query).ConfigureAwait(false);
|
||||||
// }
|
|
||||||
|
|
||||||
// public static async Task<MangaResult> GetMangaData(string query)
|
await channel.SendMessageAsync(result.ToString() ?? "`No manga found.`").ConfigureAwait(false);
|
||||||
// {
|
}
|
||||||
// if (string.IsNullOrWhiteSpace(query))
|
|
||||||
// throw new ArgumentNullException(nameof(query));
|
|
||||||
|
|
||||||
// await RefreshAnilistToken().ConfigureAwait(false);
|
private async Task<AnimeResult> GetAnimeData(string query)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(query))
|
||||||
|
throw new ArgumentNullException(nameof(query));
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await RefreshAnilistToken().ConfigureAwait(false);
|
||||||
|
|
||||||
// var link = "http://anilist.co/api/anime/search/" + Uri.EscapeUriString(query);
|
var link = "http://anilist.co/api/anime/search/" + Uri.EscapeUriString(query);
|
||||||
// var smallContent = "";
|
using (var http = new HttpClient())
|
||||||
// var cl = new RestSharp.RestClient("http://anilist.co/api");
|
{
|
||||||
// var rq = new RestSharp.RestRequest("/manga/search/" + Uri.EscapeUriString(query));
|
var res = await http.GetStringAsync("http://anilist.co/api/anime/search/" + Uri.EscapeUriString(query) + $"?access_token={anilistToken}").ConfigureAwait(false);
|
||||||
// rq.AddParameter("access_token", token);
|
var smallObj = JArray.Parse(res)[0];
|
||||||
// smallContent = cl.Execute(rq).Content;
|
var aniData = await http.GetStringAsync("http://anilist.co/api/anime/" + smallObj["id"] + $"?access_token={anilistToken}").ConfigureAwait(false);
|
||||||
// var smallObj = JArray.Parse(smallContent)[0];
|
|
||||||
|
|
||||||
// rq = new RestSharp.RestRequest("/manga/" + smallObj["id"]);
|
return await Task.Run(() => JsonConvert.DeserializeObject<AnimeResult>(aniData)).ConfigureAwait(false);
|
||||||
// rq.AddParameter("access_token", token);
|
}
|
||||||
// var content = cl.Execute(rq).Content;
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
_log.Warn(ex, "Failed anime search for {0}", query);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// return await Task.Run(() => JsonConvert.DeserializeObject<MangaResult>(content)).ConfigureAwait(false);
|
private async Task RefreshAnilistToken()
|
||||||
// }
|
{
|
||||||
// }
|
if (DateTime.Now - lastRefresh > TimeSpan.FromMinutes(29))
|
||||||
//}
|
lastRefresh = DateTime.Now;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var headers = new Dictionary<string, string> {
|
||||||
|
{"grant_type", "client_credentials"},
|
||||||
|
{"client_id", "kwoth-w0ki9"},
|
||||||
|
{"client_secret", "Qd6j4FIAi1ZK6Pc7N7V4Z"},
|
||||||
|
};
|
||||||
|
using (var http = new HttpClient())
|
||||||
|
{
|
||||||
|
http.AddFakeHeaders();
|
||||||
|
var formContent = new FormUrlEncodedContent(headers);
|
||||||
|
var response = await http.PostAsync("http://anilist.co/api/auth/access_token", formContent).ConfigureAwait(false);
|
||||||
|
var stringContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||||
|
anilistToken = JObject.Parse(stringContent)["access_token"].ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<MangaResult> GetMangaData(string query)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(query))
|
||||||
|
throw new ArgumentNullException(nameof(query));
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await RefreshAnilistToken().ConfigureAwait(false);
|
||||||
|
using (var http = new HttpClient())
|
||||||
|
{
|
||||||
|
var res = await http.GetStringAsync("http://anilist.co/api/manga/search/" + Uri.EscapeUriString(query) + $"?access_token={anilistToken}").ConfigureAwait(false);
|
||||||
|
var smallObj = JArray.Parse(res)[0];
|
||||||
|
var aniData = await http.GetStringAsync("http://anilist.co/api/manga/" + smallObj["id"] + $"?access_token={anilistToken}").ConfigureAwait(false);
|
||||||
|
|
||||||
|
return await Task.Run(() => JsonConvert.DeserializeObject<MangaResult>(aniData)).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_log.Warn(ex, "Failed anime search for {0}", query);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -14,7 +14,7 @@ namespace NadekoBot.Modules.Searches
|
|||||||
[Group]
|
[Group]
|
||||||
public partial class Searches
|
public partial class Searches
|
||||||
{
|
{
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public static async Task Calculate(IUserMessage msg, [Remainder] string expression)
|
public static async Task Calculate(IUserMessage msg, [Remainder] string expression)
|
||||||
{
|
{
|
||||||
@ -41,7 +41,7 @@ namespace NadekoBot.Modules.Searches
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task CalcOps(IUserMessage msg)
|
public async Task CalcOps(IUserMessage msg)
|
||||||
{
|
{
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
// internal override void Init(CommandGroupBuilder cgb)
|
// public override void Init(CommandGroupBuilder cgb)
|
||||||
// {
|
// {
|
||||||
// cgb.CreateCommand(Module.Prefix + "convert")
|
// cgb.CreateCommand(Module.Prefix + "convert")
|
||||||
// .Description($"Convert quantities from>to. | `{Prefix}convert m>km 1000`")
|
// .Description($"Convert quantities from>to. | `{Prefix}convert m>km 1000`")
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using NadekoBot.Attributes;
|
using NadekoBot.Attributes;
|
||||||
using NadekoBot.Modules.Searches.Models;
|
using NadekoBot.Modules.Searches.Models;
|
||||||
|
using NadekoBot.Services;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using NLog;
|
using NLog;
|
||||||
@ -19,7 +20,6 @@ namespace NadekoBot.Modules.Searches
|
|||||||
[Group]
|
[Group]
|
||||||
public class JokeCommands
|
public class JokeCommands
|
||||||
{
|
{
|
||||||
//todo DB
|
|
||||||
private List<WoWJoke> wowJokes = new List<WoWJoke>();
|
private List<WoWJoke> wowJokes = new List<WoWJoke>();
|
||||||
private List<MagicItem> magicItems;
|
private List<MagicItem> magicItems;
|
||||||
private Logger _log;
|
private Logger _log;
|
||||||
@ -42,7 +42,7 @@ namespace NadekoBot.Modules.Searches
|
|||||||
_log.Warn("data/magicitems.json is missing. Magic items are not loaded.");
|
_log.Warn("data/magicitems.json is missing. Magic items are not loaded.");
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Yomama(IUserMessage umsg)
|
public async Task Yomama(IUserMessage umsg)
|
||||||
{
|
{
|
||||||
@ -54,7 +54,7 @@ namespace NadekoBot.Modules.Searches
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Randjoke(IUserMessage umsg)
|
public async Task Randjoke(IUserMessage umsg)
|
||||||
{
|
{
|
||||||
@ -66,7 +66,7 @@ namespace NadekoBot.Modules.Searches
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task ChuckNorris(IUserMessage umsg)
|
public async Task ChuckNorris(IUserMessage umsg)
|
||||||
{
|
{
|
||||||
@ -78,7 +78,7 @@ namespace NadekoBot.Modules.Searches
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task WowJoke(IUserMessage umsg)
|
public async Task WowJoke(IUserMessage umsg)
|
||||||
{
|
{
|
||||||
@ -87,15 +87,15 @@ namespace NadekoBot.Modules.Searches
|
|||||||
if (!wowJokes.Any())
|
if (!wowJokes.Any())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
await channel.SendMessageAsync(wowJokes[new Random().Next(0, wowJokes.Count)].ToString());
|
await channel.SendMessageAsync(wowJokes[new NadekoRandom().Next(0, wowJokes.Count)].ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task MagicItem(IUserMessage umsg)
|
public async Task MagicItem(IUserMessage umsg)
|
||||||
{
|
{
|
||||||
var channel = (ITextChannel)umsg.Channel;
|
var channel = (ITextChannel)umsg.Channel;
|
||||||
var rng = new Random();
|
var rng = new NadekoRandom();
|
||||||
var item = magicItems[rng.Next(0, magicItems.Count)].ToString();
|
var item = magicItems[rng.Next(0, magicItems.Count)].ToString();
|
||||||
|
|
||||||
await channel.SendMessageAsync(item).ConfigureAwait(false);
|
await channel.SendMessageAsync(item).ConfigureAwait(false);
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using NadekoBot.Attributes;
|
using NadekoBot.Attributes;
|
||||||
using NadekoBot.Extensions;
|
using NadekoBot.Extensions;
|
||||||
|
using NadekoBot.Services;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -31,7 +32,7 @@ namespace NadekoBot.Modules.Searches
|
|||||||
"Doesn't matter what you ban really. Enemy will ban your main and you will lose." };
|
"Doesn't matter what you ban really. Enemy will ban your main and you will lose." };
|
||||||
|
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Lolban(IUserMessage umsg)
|
public async Task Lolban(IUserMessage umsg)
|
||||||
{
|
{
|
||||||
@ -52,7 +53,7 @@ namespace NadekoBot.Modules.Searches
|
|||||||
var dataList = data.Distinct(new ChampionNameComparer()).Take(showCount).ToList();
|
var dataList = data.Distinct(new ChampionNameComparer()).Take(showCount).ToList();
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
sb.AppendLine($"**Showing {dataList.Count} top banned champions.**");
|
sb.AppendLine($"**Showing {dataList.Count} top banned champions.**");
|
||||||
sb.AppendLine($"`{trashTalk[new Random().Next(0, trashTalk.Length)]}`");
|
sb.AppendLine($"`{trashTalk[new NadekoRandom().Next(0, trashTalk.Length)]}`");
|
||||||
for (var i = 0; i < dataList.Count; i++)
|
for (var i = 0; i < dataList.Count; i++)
|
||||||
{
|
{
|
||||||
if (i % 2 == 0 && i != 0)
|
if (i % 2 == 0 && i != 0)
|
||||||
@ -113,7 +114,7 @@ namespace NadekoBot.Modules.Searches
|
|||||||
// public float StatScore { get; set; }
|
// public float StatScore { get; set; }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// internal override void Init(CommandGroupBuilder cgb)
|
// public override void Init(CommandGroupBuilder cgb)
|
||||||
// {
|
// {
|
||||||
// cgb.CreateCommand(Module.Prefix + "lolchamp")
|
// cgb.CreateCommand(Module.Prefix + "lolchamp")
|
||||||
// .Description($"Shows League Of Legends champion statistics. If there are spaces/apostrophes or in the name - omit them. Optional second parameter is a role. |`{Prefix}lolchamp Riven` or `{Prefix}lolchamp Annie sup`")
|
// .Description($"Shows League Of Legends champion statistics. If there are spaces/apostrophes or in the name - omit them. Optional second parameter is a role. |`{Prefix}lolchamp Riven` or `{Prefix}lolchamp Annie sup`")
|
||||||
|
@ -15,7 +15,7 @@ namespace NadekoBot.Modules.Searches
|
|||||||
{
|
{
|
||||||
public partial class Searches
|
public partial class Searches
|
||||||
{
|
{
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Memelist(IUserMessage umsg)
|
public async Task Memelist(IUserMessage umsg)
|
||||||
{
|
{
|
||||||
@ -29,7 +29,7 @@ namespace NadekoBot.Modules.Searches
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Memegen(IUserMessage umsg, string meme, string topText, string botText)
|
public async Task Memegen(IUserMessage umsg, string meme, string topText, string botText)
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
namespace NadekoBot.Classes.JSONModels
|
namespace NadekoBot.Modules.Searches.Models
|
||||||
{
|
{
|
||||||
public class AnimeResult
|
public class AnimeResult
|
||||||
{
|
{
|
@ -1,4 +1,4 @@
|
|||||||
namespace NadekoBot.Classes.JSONModels
|
namespace NadekoBot.Modules.Searches.Models
|
||||||
{
|
{
|
||||||
public class MangaResult
|
public class MangaResult
|
||||||
{
|
{
|
@ -0,0 +1,11 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace NadekoBot.Modules.Searches.Commands.Models
|
||||||
|
{
|
||||||
|
public class MeasurementUnit
|
||||||
|
{
|
||||||
|
public List<string> Triggers { get; set; }
|
||||||
|
public string UnitType { get; set; }
|
||||||
|
public decimal Modifier { get; set; }
|
||||||
|
}
|
||||||
|
}
|
14
src/NadekoBot/Modules/Searches/Commands/Models/Rates.cs
Normal file
14
src/NadekoBot/Modules/Searches/Commands/Models/Rates.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace NadekoBot.Modules.Searches.Commands.Models
|
||||||
|
{
|
||||||
|
public class Rates
|
||||||
|
{
|
||||||
|
public string Base { get; set; }
|
||||||
|
public DateTime Date { get; set; }
|
||||||
|
[JsonProperty("rates")]
|
||||||
|
public Dictionary<string, decimal> ConversionRates { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -25,7 +25,7 @@ namespace NadekoBot.Modules.Searches
|
|||||||
{
|
{
|
||||||
_log = LogManager.GetCurrentClassLogger();
|
_log = LogManager.GetCurrentClassLogger();
|
||||||
}
|
}
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Osu(IUserMessage umsg, string usr, string mode)
|
public async Task Osu(IUserMessage umsg, string usr, string mode)
|
||||||
{
|
{
|
||||||
@ -58,7 +58,7 @@ namespace NadekoBot.Modules.Searches
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Osub(IUserMessage umsg, [Remainder] string map)
|
public async Task Osub(IUserMessage umsg, [Remainder] string map)
|
||||||
{
|
{
|
||||||
@ -95,7 +95,7 @@ namespace NadekoBot.Modules.Searches
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Osu5(IUserMessage umsg, string user, [Remainder] string mode)
|
public async Task Osu5(IUserMessage umsg, string user, [Remainder] string mode)
|
||||||
{
|
{
|
||||||
|
@ -15,7 +15,6 @@ namespace NadekoBot.Modules.Searches
|
|||||||
[Group]
|
[Group]
|
||||||
public class PokemonSearchCommands
|
public class PokemonSearchCommands
|
||||||
{
|
{
|
||||||
//todo DB
|
|
||||||
private static Dictionary<string, SearchPokemon> pokemons = new Dictionary<string, SearchPokemon>();
|
private static Dictionary<string, SearchPokemon> pokemons = new Dictionary<string, SearchPokemon>();
|
||||||
private static Dictionary<string, SearchPokemonAbility> pokemonAbilities = new Dictionary<string, SearchPokemonAbility>();
|
private static Dictionary<string, SearchPokemonAbility> pokemonAbilities = new Dictionary<string, SearchPokemonAbility>();
|
||||||
|
|
||||||
@ -39,7 +38,7 @@ namespace NadekoBot.Modules.Searches
|
|||||||
_log.Warn(PokemonAbilitiesFile + " is missing. Pokemon abilities not loaded.");
|
_log.Warn(PokemonAbilitiesFile + " is missing. Pokemon abilities not loaded.");
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Pokemon(IUserMessage umsg, [Remainder] string pokemon = null)
|
public async Task Pokemon(IUserMessage umsg, [Remainder] string pokemon = null)
|
||||||
{
|
{
|
||||||
@ -60,7 +59,7 @@ namespace NadekoBot.Modules.Searches
|
|||||||
await channel.SendMessageAsync("`No pokemon found.`");
|
await channel.SendMessageAsync("`No pokemon found.`");
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task PokemonAbility(IUserMessage umsg, [Remainder] string ability = null)
|
public async Task PokemonAbility(IUserMessage umsg, [Remainder] string ability = null)
|
||||||
{
|
{
|
||||||
|
@ -1,348 +1,288 @@
|
|||||||
//using Discord.Commands;
|
using Discord.Commands;
|
||||||
//using NadekoBot.Classes;
|
using Newtonsoft.Json.Linq;
|
||||||
//using Newtonsoft.Json.Linq;
|
using System;
|
||||||
//using System;
|
using System.Collections.Concurrent;
|
||||||
//using System.Collections.Concurrent;
|
using System.Linq;
|
||||||
//using System.Linq;
|
using System.Threading.Tasks;
|
||||||
//using System.Threading.Tasks;
|
using Discord;
|
||||||
//using Discord;
|
using NadekoBot.Services;
|
||||||
//using NadekoBot.Services;
|
using System.Threading;
|
||||||
//using System.Threading;
|
using NadekoBot.Services.Database;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using NadekoBot.Services.Database.Models;
|
||||||
|
using System.Net.Http;
|
||||||
|
using Discord.WebSocket;
|
||||||
|
using NadekoBot.Attributes;
|
||||||
|
|
||||||
//todo DB
|
namespace NadekoBot.Modules.Searches
|
||||||
//namespace NadekoBot.Modules.Searches
|
{
|
||||||
//{
|
public partial class Searches
|
||||||
// public partial class Searches
|
{
|
||||||
// {
|
[Group]
|
||||||
// [Group]
|
public class StreamNotificationCommands
|
||||||
// public class StreamNotificationCommands
|
{
|
||||||
// {
|
private Timer checkTimer { get; }
|
||||||
// private readonly Timer checkTimer;
|
private ConcurrentDictionary<string, Tuple<bool, string>> cachedStatuses = new ConcurrentDictionary<string, Tuple<bool, string>>();
|
||||||
// private ConcurrentDictionary<string, Tuple<bool, string>> cachedStatuses = new ConcurrentDictionary<string, Tuple<bool, string>>();
|
private bool FirstPass { get; set; } = true;
|
||||||
// private bool FirstPass { get; set; } = true;
|
|
||||||
|
|
||||||
// public StreamNotifications(DiscordModule module)
|
public StreamNotificationCommands()
|
||||||
// {
|
{
|
||||||
// checkTimer = new Timer(async (state) =>
|
checkTimer = new Timer(async (state) =>
|
||||||
// {
|
{
|
||||||
// cachedStatuses.Clear();
|
cachedStatuses.Clear();
|
||||||
// try
|
try
|
||||||
// {
|
{
|
||||||
// var streams = SpecificConfigurations.Default.AllConfigs.SelectMany(c => c.ObservingStreams);
|
IEnumerable<FollowedStream> streams;
|
||||||
// if (!streams.Any()) return;
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
// foreach (var stream in streams)
|
{
|
||||||
// {
|
streams = uow.GuildConfigs.GetAllFollowedStreams();
|
||||||
// Tuple<bool, string> data;
|
}
|
||||||
// try
|
foreach (var stream in streams)
|
||||||
// {
|
{
|
||||||
// data = await GetStreamStatus(stream).ConfigureAwait(false);
|
Tuple<bool, string> data;
|
||||||
// }
|
try
|
||||||
// catch
|
{
|
||||||
// {
|
data = await GetStreamStatus(stream).ConfigureAwait(false);
|
||||||
// continue;
|
}
|
||||||
// }
|
catch
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// if (data.Item1 != stream.LastStatus)
|
if (data.Item1 != stream.LastStatus)
|
||||||
// {
|
{
|
||||||
// stream.LastStatus = data.Item1;
|
stream.LastStatus = data.Item1;
|
||||||
// if (FirstPass)
|
if (FirstPass)
|
||||||
// continue;
|
continue;
|
||||||
// var server = NadekoBot.Client.GetServer(stream.ServerId);
|
var server = NadekoBot.Client.GetGuild(stream.GuildId);
|
||||||
// var channel = server?.GetChannel(stream.ChannelId);
|
var channel = server?.GetTextChannel(stream.ChannelId);
|
||||||
// if (channel == null)
|
if (channel == null)
|
||||||
// continue;
|
continue;
|
||||||
// var msg = $"`{stream.Username}`'s stream is now " +
|
var msg = $"`{stream.Username}`'s stream is now " +
|
||||||
// $"**{(data.Item1 ? "ONLINE" : "OFFLINE")}** with " +
|
$"**{(data.Item1 ? "ONLINE" : "OFFLINE")}** with " +
|
||||||
// $"**{data.Item2}** viewers.";
|
$"**{data.Item2}** viewers.";
|
||||||
// if (stream.LastStatus)
|
if (stream.LastStatus)
|
||||||
// if (stream.Type == StreamNotificationConfig.StreamType.Hitbox)
|
if (stream.Type == FollowedStream.FollowedStreamType.Hitbox)
|
||||||
// msg += $"\n`Here is the Link:`【 http://www.hitbox.tv/{stream.Username}/ 】";
|
msg += $"\n`Here is the Link:`【 http://www.hitbox.tv/{stream.Username}/ 】";
|
||||||
// else if (stream.Type == StreamNotificationConfig.StreamType.Twitch)
|
else if (stream.Type == FollowedStream.FollowedStreamType.Twitch)
|
||||||
// msg += $"\n`Here is the Link:`【 http://www.twitch.tv/{stream.Username}/ 】";
|
msg += $"\n`Here is the Link:`【 http://www.twitch.tv/{stream.Username}/ 】";
|
||||||
// else if (stream.Type == StreamNotificationConfig.StreamType.Beam)
|
else if (stream.Type == FollowedStream.FollowedStreamType.Beam)
|
||||||
// msg += $"\n`Here is the Link:`【 http://www.beam.pro/{stream.Username}/ 】";
|
msg += $"\n`Here is the Link:`【 http://www.beam.pro/{stream.Username}/ 】";
|
||||||
// else if (stream.Type == StreamNotificationConfig.StreamType.YoutubeGaming)
|
//else if (stream.Type == FollowedStream.FollowedStreamType.YoutubeGaming)
|
||||||
// msg += $"\n`Here is the Link:`【 not implemented yet - {stream.Username} 】";
|
// msg += $"\n`Here is the Link:`【 not implemented yet - {stream.Username} 】";
|
||||||
// await channel.SendMessageAsync(msg).ConfigureAwait(false);
|
await channel.SendMessageAsync(msg).ConfigureAwait(false);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// FirstPass = false;
|
FirstPass = false;
|
||||||
// }
|
}
|
||||||
// catch { }
|
catch { }
|
||||||
// }, null, TimeSpan.Zero, TimeSpan.FromSeconds(15));
|
}, null, TimeSpan.Zero, TimeSpan.FromSeconds(15));
|
||||||
// }
|
}
|
||||||
|
|
||||||
// public StreamNotifications(ILocalization loc, CommandService cmds, IBotConfiguration config, DiscordSocketClient client) : base(loc, cmds, config, client)
|
private async Task<Tuple<bool, string>> GetStreamStatus(FollowedStream stream, bool checkCache = true)
|
||||||
// {
|
{
|
||||||
// }
|
bool isLive;
|
||||||
|
string response;
|
||||||
|
JObject data;
|
||||||
|
Tuple<bool, string> result;
|
||||||
|
switch (stream.Type)
|
||||||
|
{
|
||||||
|
case FollowedStream.FollowedStreamType.Hitbox:
|
||||||
|
var hitboxUrl = $"https://api.hitbox.tv/media/status/{stream.Username}";
|
||||||
|
if (checkCache && cachedStatuses.TryGetValue(hitboxUrl, out result))
|
||||||
|
return result;
|
||||||
|
using (var http = new HttpClient())
|
||||||
|
{
|
||||||
|
response = await http.GetStringAsync(hitboxUrl).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
data = JObject.Parse(response);
|
||||||
|
isLive = data["media_is_live"].ToString() == "1";
|
||||||
|
result = new Tuple<bool, string>(isLive, data["media_views"].ToString());
|
||||||
|
cachedStatuses.TryAdd(hitboxUrl, result);
|
||||||
|
return result;
|
||||||
|
case FollowedStream.FollowedStreamType.Twitch:
|
||||||
|
var twitchUrl = $"https://api.twitch.tv/kraken/streams/{Uri.EscapeUriString(stream.Username)}";
|
||||||
|
if (checkCache && cachedStatuses.TryGetValue(twitchUrl, out result))
|
||||||
|
return result;
|
||||||
|
using (var http = new HttpClient())
|
||||||
|
{
|
||||||
|
response = await http.GetStringAsync(twitchUrl).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
data = JObject.Parse(response);
|
||||||
|
isLive = !string.IsNullOrWhiteSpace(data["stream"].ToString());
|
||||||
|
result = new Tuple<bool, string>(isLive, isLive ? data["stream"]["viewers"].ToString() : "0");
|
||||||
|
cachedStatuses.TryAdd(twitchUrl, result);
|
||||||
|
return result;
|
||||||
|
case FollowedStream.FollowedStreamType.Beam:
|
||||||
|
var beamUrl = $"https://beam.pro/api/v1/channels/{stream.Username}";
|
||||||
|
if (checkCache && cachedStatuses.TryGetValue(beamUrl, out result))
|
||||||
|
return result;
|
||||||
|
using (var http = new HttpClient())
|
||||||
|
{
|
||||||
|
response = await http.GetStringAsync(beamUrl).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
data = JObject.Parse(response);
|
||||||
|
isLive = data["online"].ToObject<bool>() == true;
|
||||||
|
result = new Tuple<bool, string>(isLive, data["viewersCurrent"].ToString());
|
||||||
|
cachedStatuses.TryAdd(beamUrl, result);
|
||||||
|
return result;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return new Tuple<bool, string>(false, "0");
|
||||||
|
}
|
||||||
|
|
||||||
// private async Task<Tuple<bool, string>> GetStreamStatus(StreamNotificationConfig stream, bool checkCache = true)
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
// {
|
[RequireContext(ContextType.Guild)]
|
||||||
// bool isLive;
|
[RequirePermission(GuildPermission.ManageMessages)]
|
||||||
// string response;
|
public async Task Hitbox(IUserMessage msg, [Remainder] string username) =>
|
||||||
// JObject data;
|
await TrackStream((ITextChannel)msg.Channel, username, FollowedStream.FollowedStreamType.Hitbox)
|
||||||
// Tuple<bool, string> result;
|
.ConfigureAwait(false);
|
||||||
// switch (stream.Type)
|
|
||||||
// {
|
|
||||||
// case StreamNotificationConfig.StreamType.Hitbox:
|
|
||||||
// var hitboxUrl = $"https://api.hitbox.tv/media/status/{stream.Username}";
|
|
||||||
// if (checkCache && cachedStatuses.TryGetValue(hitboxUrl, out result))
|
|
||||||
// return result;
|
|
||||||
// response = await http.GetStringAsync(hitboxUrl).ConfigureAwait(false);
|
|
||||||
// data = JObject.Parse(response);
|
|
||||||
// isLive = data["media_is_live"].ToString() == "1";
|
|
||||||
// result = new Tuple<bool, string>(isLive, data["media_views"].ToString());
|
|
||||||
// cachedStatuses.TryAdd(hitboxUrl, result);
|
|
||||||
// return result;
|
|
||||||
// case StreamNotificationConfig.StreamType.Twitch:
|
|
||||||
// var twitchUrl = $"https://api.twitch.tv/kraken/streams/{Uri.EscapeUriString(stream.Username)}";
|
|
||||||
// if (checkCache && cachedStatuses.TryGetValue(twitchUrl, out result))
|
|
||||||
// return result;
|
|
||||||
// response = await http.GetStringAsync(twitchUrl).ConfigureAwait(false);
|
|
||||||
// data = JObject.Parse(response);
|
|
||||||
// isLive = !string.IsNullOrWhiteSpace(data["stream"].ToString());
|
|
||||||
// result = new Tuple<bool, string>(isLive, isLive ? data["stream"]["viewers"].ToString() : "0");
|
|
||||||
// cachedStatuses.TryAdd(twitchUrl, result);
|
|
||||||
// return result;
|
|
||||||
// case StreamNotificationConfig.StreamType.Beam:
|
|
||||||
// var beamUrl = $"https://beam.pro/api/v1/channels/{stream.Username}";
|
|
||||||
// if (checkCache && cachedStatuses.TryGetValue(beamUrl, out result))
|
|
||||||
// return result;
|
|
||||||
// response = await http.GetStringAsync(beamUrl).ConfigureAwait(false);
|
|
||||||
// data = JObject.Parse(response);
|
|
||||||
// isLive = data["online"].ToObject<bool>() == true;
|
|
||||||
// result = new Tuple<bool, string>(isLive, data["viewersCurrent"].ToString());
|
|
||||||
// cachedStatuses.TryAdd(beamUrl, result);
|
|
||||||
// return result;
|
|
||||||
// default:
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// return new Tuple<bool, string>(false, "0");
|
|
||||||
// }
|
|
||||||
|
|
||||||
// internal override void Init(CommandGroupBuilder cgb)
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
// {
|
[RequireContext(ContextType.Guild)]
|
||||||
// cgb.CreateCommand(Module.Prefix + "hitbox")
|
[RequirePermission(GuildPermission.ManageMessages)]
|
||||||
// .Alias(Module.Prefix + "hb")
|
public async Task Twitch(IUserMessage msg, [Remainder] string username) =>
|
||||||
// .Description("Notifies this channel when a certain user starts streaming." +
|
await TrackStream((ITextChannel)msg.Channel, username, FollowedStream.FollowedStreamType.Twitch)
|
||||||
// $" | `{Prefix}hitbox SomeStreamer`")
|
.ConfigureAwait(false);
|
||||||
// .Parameter("username", ParameterType.Unparsed)
|
|
||||||
// .AddCheck(SimpleCheckers.ManageServer())
|
|
||||||
// .Do(TrackStream(StreamNotificationConfig.StreamType.Hitbox));
|
|
||||||
|
|
||||||
// cgb.CreateCommand(Module.Prefix + "twitch")
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
// .Alias(Module.Prefix + "tw")
|
[RequireContext(ContextType.Guild)]
|
||||||
// .Description("Notifies this channel when a certain user starts streaming." +
|
[RequirePermission(GuildPermission.ManageMessages)]
|
||||||
// $" | `{Prefix}twitch SomeStreamer`")
|
public async Task Beam(IUserMessage msg, [Remainder] string username) =>
|
||||||
// .AddCheck(SimpleCheckers.ManageServer())
|
await TrackStream((ITextChannel)msg.Channel, username, FollowedStream.FollowedStreamType.Beam)
|
||||||
// .Parameter("username", ParameterType.Unparsed)
|
.ConfigureAwait(false);
|
||||||
// .Do(TrackStream(StreamNotificationConfig.StreamType.Twitch));
|
|
||||||
|
|
||||||
// cgb.CreateCommand(Module.Prefix + "beam")
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
// .Alias(Module.Prefix + "bm")
|
[RequireContext(ContextType.Guild)]
|
||||||
// .Description("Notifies this channel when a certain user starts streaming." +
|
public async Task ListStreams(IUserMessage imsg)
|
||||||
// $" | `{Prefix}beam SomeStreamer`")
|
{
|
||||||
// .AddCheck(SimpleCheckers.ManageServer())
|
var channel = (ITextChannel)imsg.Channel;
|
||||||
// .Parameter("username", ParameterType.Unparsed)
|
|
||||||
// .Do(TrackStream(StreamNotificationConfig.StreamType.Beam));
|
|
||||||
|
|
||||||
// cgb.CreateCommand(Module.Prefix + "checkhitbox")
|
IEnumerable<FollowedStream> streams;
|
||||||
// .Alias(Module.Prefix + "chhb")
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
// .Description("Checks if a certain user is streaming on the hitbox platform." +
|
{
|
||||||
// $" | `{Prefix}chhb SomeStreamer`")
|
streams = uow.GuildConfigs.For(channel.Guild.Id).FollowedStreams;
|
||||||
// .Parameter("username", ParameterType.Unparsed)
|
}
|
||||||
// .AddCheck(SimpleCheckers.ManageServer())
|
|
||||||
// .Do(async e =>
|
|
||||||
// {
|
|
||||||
// var stream = username?.Trim();
|
|
||||||
// if (string.IsNullOrWhiteSpace(stream))
|
|
||||||
// return;
|
|
||||||
// try
|
|
||||||
// {
|
|
||||||
// var streamStatus = (await GetStreamStatus(new StreamNotificationConfig
|
|
||||||
// {
|
|
||||||
// Username = stream,
|
|
||||||
// Type = StreamNotificationConfig.StreamType.Hitbox
|
|
||||||
// }));
|
|
||||||
// if (streamStatus.Item1)
|
|
||||||
// {
|
|
||||||
// await channel.SendMessageAsync($"`Streamer {streamStatus.Item2} is online.`");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// catch
|
|
||||||
// {
|
|
||||||
// await channel.SendMessageAsync("No channel found.");
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
// cgb.CreateCommand(Module.Prefix + "checktwitch")
|
if (!streams.Any())
|
||||||
// .Alias(Module.Prefix + "chtw")
|
{
|
||||||
// .Description("Checks if a certain user is streaming on the twitch platform." +
|
await channel.SendMessageAsync("You are not following any streams on this server.").ConfigureAwait(false);
|
||||||
// $" | `{Prefix}chtw SomeStreamer`")
|
return;
|
||||||
// .AddCheck(SimpleCheckers.ManageServer())
|
}
|
||||||
// .Parameter("username", ParameterType.Unparsed)
|
|
||||||
// .Do(async e =>
|
|
||||||
// {
|
|
||||||
// var stream = username?.Trim();
|
|
||||||
// if (string.IsNullOrWhiteSpace(stream))
|
|
||||||
// return;
|
|
||||||
// try
|
|
||||||
// {
|
|
||||||
// var streamStatus = (await GetStreamStatus(new StreamNotificationConfig
|
|
||||||
// {
|
|
||||||
// Username = stream,
|
|
||||||
// Type = StreamNotificationConfig.StreamType.Twitch
|
|
||||||
// }));
|
|
||||||
// if (streamStatus.Item1)
|
|
||||||
// {
|
|
||||||
// await channel.SendMessageAsync($"`Streamer {streamStatus.Item2} is online.`");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// catch
|
|
||||||
// {
|
|
||||||
// await channel.SendMessageAsync("No channel found.");
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
// cgb.CreateCommand(Module.Prefix + "checkbeam")
|
var text = string.Join("\n", streams.Select(snc =>
|
||||||
// .Alias(Module.Prefix + "chbm")
|
{
|
||||||
// .Description("Checks if a certain user is streaming on the beam platform." +
|
return $"`{snc.Username}`'s stream on **{channel.Guild.GetTextChannel(snc.ChannelId)?.Name}** channel. 【`{snc.Type.ToString()}`】";
|
||||||
// $" | `{Prefix}chbm SomeStreamer`")
|
}));
|
||||||
// .AddCheck(SimpleCheckers.ManageServer())
|
|
||||||
// .Parameter("username", ParameterType.Unparsed)
|
|
||||||
// .Do(async e =>
|
|
||||||
// {
|
|
||||||
// var stream = username?.Trim();
|
|
||||||
// if (string.IsNullOrWhiteSpace(stream))
|
|
||||||
// return;
|
|
||||||
// try
|
|
||||||
// {
|
|
||||||
// var streamStatus = (await GetStreamStatus(new StreamNotificationConfig
|
|
||||||
// {
|
|
||||||
// Username = stream,
|
|
||||||
// Type = StreamNotificationConfig.StreamType.Beam
|
|
||||||
// }));
|
|
||||||
// if (streamStatus.Item1)
|
|
||||||
// {
|
|
||||||
// await channel.SendMessageAsync($"`Streamer {streamStatus.Item2} is online.`");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// catch
|
|
||||||
// {
|
|
||||||
// await channel.SendMessageAsync("No channel found.");
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
// cgb.CreateCommand(Module.Prefix + "removestream")
|
await channel.SendMessageAsync($"You are following **{streams.Count()}** streams on this server.\n\n" + text).ConfigureAwait(false);
|
||||||
// .Alias(Module.Prefix + "rms")
|
}
|
||||||
// .Description("Removes notifications of a certain streamer on this channel." +
|
|
||||||
// $" | `{Prefix}rms SomeGuy`")
|
|
||||||
// .AddCheck(SimpleCheckers.ManageServer())
|
|
||||||
// .Parameter("username", ParameterType.Unparsed)
|
|
||||||
// .Do(async e =>
|
|
||||||
// {
|
|
||||||
// var username = username?.ToLower().Trim();
|
|
||||||
// if (string.IsNullOrWhiteSpace(username))
|
|
||||||
// return;
|
|
||||||
|
|
||||||
// var config = SpecificConfigurations.Default.Of(e.Server.Id);
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
|
[RequireContext(ContextType.Guild)]
|
||||||
|
public async Task RemoveStream(IUserMessage msg, [Remainder] string username)
|
||||||
|
{
|
||||||
|
var channel = (ITextChannel)msg.Channel;
|
||||||
|
|
||||||
// var toRemove = config.ObservingStreams
|
username = username.ToUpperInvariant().Trim();
|
||||||
// .FirstOrDefault(snc => snc.ChannelId == e.Channel.Id &&
|
|
||||||
// snc.Username.ToLower().Trim() == username);
|
|
||||||
// if (toRemove == null)
|
|
||||||
// {
|
|
||||||
// await channel.SendMessageAsync(":anger: No such stream.").ConfigureAwait(false);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// config.ObservingStreams.Remove(toRemove);
|
FollowedStream toRemove;
|
||||||
// await ConfigHandler.SaveConfig().ConfigureAwait(false);
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
// await channel.SendMessageAsync($":ok: Removed `{toRemovumsg.Authorname}`'s stream from notifications.").ConfigureAwait(false);
|
{
|
||||||
// });
|
var config = uow.GuildConfigs.For(channel.Guild.Id);
|
||||||
|
var streams = config.FollowedStreams;
|
||||||
|
toRemove = streams.Where(fs => fs.ChannelId == channel.Id && fs.Username.ToUpperInvariant() == username).FirstOrDefault();
|
||||||
|
if (toRemove != null)
|
||||||
|
{
|
||||||
|
config.FollowedStreams = streams.Except(new[] { toRemove }).ToList();
|
||||||
|
await uow.CompleteAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (toRemove == null)
|
||||||
|
{
|
||||||
|
await channel.SendMessageAsync(":anger: No such stream.").ConfigureAwait(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await channel.SendMessageAsync($":ok: Removed `{toRemove.Username}`'s stream ({toRemove.Type}) from notifications.").ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
// cgb.CreateCommand(Module.Prefix + "liststreams")
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
// .Alias(Module.Prefix + "ls")
|
[RequireContext(ContextType.Guild)]
|
||||||
// .Description("Lists all streams you are following on this server." +
|
public async Task CheckStream(IUserMessage imsg, FollowedStream.FollowedStreamType platform, [Remainder] string username)
|
||||||
// $" | `{Prefix}ls`")
|
{
|
||||||
// .Do(async e =>
|
var channel = (ITextChannel)imsg.Channel;
|
||||||
// {
|
|
||||||
|
|
||||||
// var config = SpecificConfigurations.Default.Of(e.Server.Id);
|
var stream = username?.Trim();
|
||||||
|
if (string.IsNullOrWhiteSpace(stream))
|
||||||
|
return;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var streamStatus = (await GetStreamStatus(new FollowedStream
|
||||||
|
{
|
||||||
|
Username = stream,
|
||||||
|
Type = platform
|
||||||
|
}));
|
||||||
|
if (streamStatus.Item1)
|
||||||
|
{
|
||||||
|
await channel.SendMessageAsync($"`Streamer {streamStatus.Item2} is online.`");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
await channel.SendMessageAsync("No channel found.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// var streams = config.ObservingStreams.Where(snc =>
|
private async Task TrackStream(ITextChannel channel, string username, FollowedStream.FollowedStreamType type)
|
||||||
// snc.ServerId == e.Server.Id);
|
{
|
||||||
|
username = username.ToUpperInvariant().Trim();
|
||||||
// var streamsArray = streams as StreamNotificationConfig[] ?? streams.ToArray();
|
var stream = new FollowedStream
|
||||||
|
{
|
||||||
// if (streamsArray.Length == 0)
|
GuildId = channel.Guild.Id,
|
||||||
// {
|
ChannelId = channel.Id,
|
||||||
// await channel.SendMessageAsync("You are not following any streams on this server.").ConfigureAwait(false);
|
Username = username,
|
||||||
// return;
|
Type = type,
|
||||||
// }
|
};
|
||||||
|
bool exists;
|
||||||
// var text = string.Join("\n", streamsArray.Select(snc =>
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
// {
|
{
|
||||||
// try
|
exists = uow.GuildConfigs.For(channel.Guild.Id).FollowedStreams.Where(fs => fs.ChannelId == channel.Id && fs.Username.ToUpperInvariant().Trim() == username).Any();
|
||||||
// {
|
}
|
||||||
// return $"`{snc.Username}`'s stream on **{e.Server.GetChannel(e.Channel.Id).Name}** channel. 【`{snc.Type.ToString()}`】";
|
if (exists)
|
||||||
// }
|
{
|
||||||
// catch { }
|
await channel.SendMessageAsync($":anger: I am already following `{username}` ({type}) stream on this channel.").ConfigureAwait(false);
|
||||||
// return "";
|
return;
|
||||||
// }));
|
}
|
||||||
|
Tuple<bool, string> data;
|
||||||
// await channel.SendMessageAsync($"You are following **{streamsArray.Length}** streams on this server.\n\n" + text).ConfigureAwait(false);
|
try
|
||||||
// });
|
{
|
||||||
// }
|
data = await GetStreamStatus(stream).ConfigureAwait(false);
|
||||||
|
}
|
||||||
// private Func<CommandEventArgs, Task> TrackStream(StreamNotificationConfig.StreamType type) =>
|
catch
|
||||||
// async e =>
|
{
|
||||||
// {
|
await channel.SendMessageAsync(":anger: Stream probably doesn't exist.").ConfigureAwait(false);
|
||||||
// var username = username?.ToLowerInvariant();
|
return;
|
||||||
// if (string.IsNullOrWhiteSpace(username))
|
}
|
||||||
// return;
|
var msg = $"Stream is currently **{(data.Item1 ? "ONLINE" : "OFFLINE")}** with **{data.Item2}** viewers";
|
||||||
|
if (data.Item1)
|
||||||
// var config = SpecificConfigurations.Default.Of(e.Server.Id);
|
if (type == FollowedStream.FollowedStreamType.Hitbox)
|
||||||
|
msg += $"\n`Here is the Link:`【 http://www.hitbox.tv/{stream.Username}/ 】";
|
||||||
// var stream = new StreamNotificationConfig
|
else if (type == FollowedStream.FollowedStreamType.Twitch)
|
||||||
// {
|
msg += $"\n`Here is the Link:`【 http://www.twitch.tv/{stream.Username}/ 】";
|
||||||
// ServerId = e.Server.Id,
|
else if (type == FollowedStream.FollowedStreamType.Beam)
|
||||||
// ChannelId = e.Channel.Id,
|
msg += $"\n`Here is the Link:`【 https://beam.pro/{stream.Username}/ 】";
|
||||||
// Username = username,
|
//else if (type == FollowedStream.FollowedStreamType.YoutubeGaming)
|
||||||
// Type = type,
|
|
||||||
// };
|
|
||||||
// var exists = config.ObservingStreams.Contains(stream);
|
|
||||||
// if (exists)
|
|
||||||
// {
|
|
||||||
// await channel.SendMessageAsync(":anger: I am already notifying that stream on this channel.").ConfigureAwait(false);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// Tuple<bool, string> data;
|
|
||||||
// try
|
|
||||||
// {
|
|
||||||
// data = await GetStreamStatus(stream).ConfigureAwait(false);
|
|
||||||
// }
|
|
||||||
// catch
|
|
||||||
// {
|
|
||||||
// await channel.SendMessageAsync(":anger: Stream probably doesn't exist.").ConfigureAwait(false);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// var msg = $"Stream is currently **{(data.Item1 ? "ONLINE" : "OFFLINE")}** with **{data.Item2}** viewers";
|
|
||||||
// if (data.Item1)
|
|
||||||
// if (type == StreamNotificationConfig.StreamType.Hitbox)
|
|
||||||
// msg += $"\n`Here is the Link:`【 http://www.hitbox.tv/{stream.Username}/ 】";
|
|
||||||
// else if (type == StreamNotificationConfig.StreamType.Twitch)
|
|
||||||
// msg += $"\n`Here is the Link:`【 http://www.twitch.tv/{stream.Username}/ 】";
|
|
||||||
// else if (type == StreamNotificationConfig.StreamType.Beam)
|
|
||||||
// msg += $"\n`Here is the Link:`【 https://beam.pro/{stream.Username}/ 】";
|
|
||||||
// else if (type == StreamNotificationConfig.StreamType.YoutubeGaming)
|
|
||||||
// msg += $"\n`Here is the Link:` not implemented yet - {stream.Username}";
|
// msg += $"\n`Here is the Link:` not implemented yet - {stream.Username}";
|
||||||
// stream.LastStatus = data.Item1;
|
stream.LastStatus = data.Item1;
|
||||||
// if (!exists)
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
// msg = $":ok: I will notify this channel when status changes.\n{msg}";
|
{
|
||||||
// await channel.SendMessageAsync(msg).ConfigureAwait(false);
|
uow.GuildConfigs.For(channel.Guild.Id).FollowedStreams.Add(stream);
|
||||||
// config.ObservingStreams.Add(stream);
|
await uow.CompleteAsync();
|
||||||
// };
|
}
|
||||||
// }
|
msg = $":ok: I will notify this channel when status changes.\n{msg}";
|
||||||
// }
|
await channel.SendMessageAsync(msg).ConfigureAwait(false);
|
||||||
//}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
201
src/NadekoBot/Modules/Searches/Commands/UnitConversion.cs
Normal file
201
src/NadekoBot/Modules/Searches/Commands/UnitConversion.cs
Normal file
@ -0,0 +1,201 @@
|
|||||||
|
using Discord;
|
||||||
|
using Discord.Commands;
|
||||||
|
using NadekoBot.Attributes;
|
||||||
|
using NadekoBot.Extensions;
|
||||||
|
using NadekoBot.Modules.Searches.Commands.Models;
|
||||||
|
using NadekoBot.Services;
|
||||||
|
using NadekoBot.Services.Database.Models;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using NLog;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Xml;
|
||||||
|
|
||||||
|
namespace NadekoBot.Modules.Searches
|
||||||
|
{
|
||||||
|
public partial class Searches
|
||||||
|
{
|
||||||
|
[Group]
|
||||||
|
public class UnitConverterCommands
|
||||||
|
{
|
||||||
|
private Logger _log;
|
||||||
|
private static Timer _timer;
|
||||||
|
public static TimeSpan Span = new TimeSpan(12, 0, 0);
|
||||||
|
public UnitConverterCommands()
|
||||||
|
{
|
||||||
|
_log = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
|
{
|
||||||
|
//need to do this the first time
|
||||||
|
if (uow.ConverterUnits.Empty())
|
||||||
|
{
|
||||||
|
var content = JsonConvert.DeserializeObject<List<MeasurementUnit>>(File.ReadAllText("units.json")).Select(u => new ConvertUnit()
|
||||||
|
{
|
||||||
|
Modifier = u.Modifier,
|
||||||
|
UnitType = u.UnitType,
|
||||||
|
InternalTrigger = string.Join("|", u.Triggers)
|
||||||
|
});
|
||||||
|
|
||||||
|
uow.ConverterUnits.AddRange(content.ToArray());
|
||||||
|
uow.Complete();
|
||||||
|
}
|
||||||
|
Units = uow.ConverterUnits.GetAll().ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_log.Warn("Could not load units: " + e.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
_timer = new Timer(new TimerCallback(UpdateCurrency), null, 0,(int)Span.TotalMilliseconds);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateCurrency(object stateInfo)
|
||||||
|
{
|
||||||
|
var currencyRates = UpdateCurrencyRates().Result;
|
||||||
|
var unitTypeString = "currency";
|
||||||
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
|
{
|
||||||
|
var toRemove = Units.Where(u => u.UnitType == unitTypeString);
|
||||||
|
Units.RemoveAll(u => u.UnitType == unitTypeString);
|
||||||
|
uow.ConverterUnits.RemoveRange(toRemove.ToArray());
|
||||||
|
var baseType = new ConvertUnit()
|
||||||
|
{
|
||||||
|
Triggers = new[] { currencyRates.Base },
|
||||||
|
Modifier = decimal.One,
|
||||||
|
UnitType = unitTypeString
|
||||||
|
};
|
||||||
|
uow.ConverterUnits.Add(baseType);
|
||||||
|
Units.Add(baseType);
|
||||||
|
var range = currencyRates.ConversionRates.Select(u => new ConvertUnit()
|
||||||
|
{
|
||||||
|
InternalTrigger = u.Key,
|
||||||
|
Modifier = u.Value,
|
||||||
|
UnitType = unitTypeString
|
||||||
|
}).ToArray();
|
||||||
|
uow.ConverterUnits.AddRange(range);
|
||||||
|
Units.AddRange(range);
|
||||||
|
|
||||||
|
uow.Complete();
|
||||||
|
}
|
||||||
|
_log.Info("Updated Currency");
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ConvertUnit> Units { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
|
[RequireContext(ContextType.Guild)]
|
||||||
|
public async Task ConvertListE(IUserMessage msg) //extended and bugged list
|
||||||
|
{
|
||||||
|
var channel = msg.Channel as IGuildChannel;
|
||||||
|
|
||||||
|
var sb = new StringBuilder("Units that can be used by the converter: \n");
|
||||||
|
var res = Units.GroupBy(x => x.UnitType);
|
||||||
|
foreach (var group in res)
|
||||||
|
{
|
||||||
|
sb.AppendLine($"{group.Key}: ```xl");
|
||||||
|
foreach (var el in group)
|
||||||
|
{
|
||||||
|
sb.Append($" [{string.Join(",", el.Triggers)}] ");
|
||||||
|
}
|
||||||
|
sb.AppendLine("```");
|
||||||
|
}
|
||||||
|
await msg.ReplyLong(sb.ToString(), breakOn: new[] { "```xl", "\n" });
|
||||||
|
}
|
||||||
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
|
[RequireContext(ContextType.Guild)]
|
||||||
|
public async Task ConvertList(IUserMessage msg)
|
||||||
|
{
|
||||||
|
var sb = new StringBuilder("Units that can be used by the converter: \n");
|
||||||
|
var res = Units.GroupBy(x => x.UnitType);
|
||||||
|
foreach (var group in res)
|
||||||
|
{
|
||||||
|
sb.AppendLine($"{group.Key}: ```xl");
|
||||||
|
sb.AppendLine(string.Join(",", group.Select(x => x.Triggers.FirstOrDefault()).OrderBy(x => x)));
|
||||||
|
sb.AppendLine("```");
|
||||||
|
}
|
||||||
|
await msg.ReplyLong(sb.ToString(), breakOn: new[] { "```xl\n", "\n" });
|
||||||
|
}
|
||||||
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
|
public async Task Convert(IUserMessage msg, string origin, string target, decimal value)
|
||||||
|
{
|
||||||
|
var originUnit = Units.Find(x => x.Triggers.Select(y => y.ToLowerInvariant()).Contains(origin.ToLowerInvariant()));
|
||||||
|
var targetUnit = Units.Find(x => x.Triggers.Select(y => y.ToLowerInvariant()).Contains(target.ToLowerInvariant()));
|
||||||
|
if (originUnit == null || targetUnit == null)
|
||||||
|
{
|
||||||
|
await msg.Reply(string.Format("Cannot convert {0} to {1}: units not found", origin, target));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (originUnit.UnitType != targetUnit.UnitType)
|
||||||
|
{
|
||||||
|
await msg.Reply(string.Format("Cannot convert {0} to {1}: types of unit are not equal", originUnit.Triggers.First(), targetUnit.Triggers.First()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
decimal res;
|
||||||
|
if (originUnit.Triggers == targetUnit.Triggers) res = value;
|
||||||
|
else if (originUnit.UnitType == "temperature")
|
||||||
|
{
|
||||||
|
//don't really care too much about efficiency, so just convert to Kelvin, then to target
|
||||||
|
switch (originUnit.Triggers.First().ToUpperInvariant())
|
||||||
|
{
|
||||||
|
case "C":
|
||||||
|
res = value + (decimal)273.15; //celcius!
|
||||||
|
break;
|
||||||
|
case "F":
|
||||||
|
res = (value + (decimal)459.67) * ((decimal)5 / 9);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res = value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//from Kelvin to target
|
||||||
|
switch (targetUnit.Triggers.First())
|
||||||
|
{
|
||||||
|
case "C":
|
||||||
|
res = value - (decimal)273.15; //celcius!
|
||||||
|
break;
|
||||||
|
case "F":
|
||||||
|
res = res * ((decimal)9 / 5) - (decimal)458.67;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//I just love currency
|
||||||
|
if (originUnit.UnitType == "currency")
|
||||||
|
{
|
||||||
|
res = (value * targetUnit.Modifier) / originUnit.Modifier;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
res = (value * originUnit.Modifier) / targetUnit.Modifier;
|
||||||
|
}
|
||||||
|
res = Math.Round(res, 2);
|
||||||
|
await msg.Reply(string.Format("{0} {1} is equal to {2} {3}", value, originUnit.Triggers.First(), res, targetUnit.Triggers.First()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task<Rates> UpdateCurrencyRates()
|
||||||
|
{
|
||||||
|
using (var http = new HttpClient())
|
||||||
|
{
|
||||||
|
var res = await http.GetStringAsync("http://api.fixer.io/latest").ConfigureAwait(false);
|
||||||
|
return JsonConvert.DeserializeObject<Rates>(res);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -16,7 +16,7 @@ using NadekoBot.Modules.Searches.IMDB;
|
|||||||
|
|
||||||
namespace NadekoBot.Modules.Searches
|
namespace NadekoBot.Modules.Searches
|
||||||
{
|
{
|
||||||
[Module("~", AppendSpace = false)]
|
[NadekoModule("Searches", "~")]
|
||||||
public partial class Searches : DiscordModule
|
public partial class Searches : DiscordModule
|
||||||
{
|
{
|
||||||
private IGoogleApiService _google { get; }
|
private IGoogleApiService _google { get; }
|
||||||
@ -26,7 +26,7 @@ namespace NadekoBot.Modules.Searches
|
|||||||
_google = youtube;
|
_google = youtube;
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Weather(IUserMessage umsg, string city, string country)
|
public async Task Weather(IUserMessage umsg, string city, string country)
|
||||||
{
|
{
|
||||||
@ -47,7 +47,7 @@ $@"🌍 **Weather for** 【{obj["target"]}】
|
|||||||
🌄 **Sunrise:** {obj["sunrise"]} 🌇 **Sunset:** {obj["sunset"]}").ConfigureAwait(false);
|
🌄 **Sunrise:** {obj["sunrise"]} 🌇 **Sunset:** {obj["sunset"]}").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Youtube(IUserMessage umsg, [Remainder] string query = null)
|
public async Task Youtube(IUserMessage umsg, [Remainder] string query = null)
|
||||||
{
|
{
|
||||||
@ -62,7 +62,7 @@ $@"🌍 **Weather for** 【{obj["target"]}】
|
|||||||
await channel.SendMessageAsync(result).ConfigureAwait(false);
|
await channel.SendMessageAsync(result).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Imdb(IUserMessage umsg, [Remainder] string query = null)
|
public async Task Imdb(IUserMessage umsg, [Remainder] string query = null)
|
||||||
{
|
{
|
||||||
@ -86,7 +86,7 @@ $@"🌍 **Weather for** 【{obj["target"]}】
|
|||||||
await channel.SendMessageAsync(result.ToString()).ConfigureAwait(false);
|
await channel.SendMessageAsync(result.ToString()).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task RandomCat(IUserMessage umsg)
|
public async Task RandomCat(IUserMessage umsg)
|
||||||
{
|
{
|
||||||
@ -99,7 +99,7 @@ $@"🌍 **Weather for** 【{obj["target"]}】
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task RandomDog(IUserMessage umsg)
|
public async Task RandomDog(IUserMessage umsg)
|
||||||
{
|
{
|
||||||
@ -110,7 +110,7 @@ $@"🌍 **Weather for** 【{obj["target"]}】
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task I(IUserMessage umsg, [Remainder] string query = null)
|
public async Task I(IUserMessage umsg, [Remainder] string query = null)
|
||||||
{
|
{
|
||||||
@ -140,7 +140,7 @@ $@"🌍 **Weather for** 【{obj["target"]}】
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Ir(IUserMessage umsg, [Remainder] string query = null)
|
public async Task Ir(IUserMessage umsg, [Remainder] string query = null)
|
||||||
{
|
{
|
||||||
@ -152,7 +152,7 @@ $@"🌍 **Weather for** 【{obj["target"]}】
|
|||||||
{
|
{
|
||||||
using (var http = new HttpClient())
|
using (var http = new HttpClient())
|
||||||
{
|
{
|
||||||
var rng = new Random();
|
var rng = new NadekoRandom();
|
||||||
var reqString = $"https://www.googleapis.com/customsearch/v1?q={Uri.EscapeDataString(query)}&cx=018084019232060951019%3Ahs5piey28-e&num=1&searchType=image&start={ rng.Next(1, 50) }&fields=items%2Flink&key={NadekoBot.Credentials.GoogleApiKey}";
|
var reqString = $"https://www.googleapis.com/customsearch/v1?q={Uri.EscapeDataString(query)}&cx=018084019232060951019%3Ahs5piey28-e&num=1&searchType=image&start={ rng.Next(1, 50) }&fields=items%2Flink&key={NadekoBot.Credentials.GoogleApiKey}";
|
||||||
var obj = JObject.Parse(await http.GetStringAsync(reqString).ConfigureAwait(false));
|
var obj = JObject.Parse(await http.GetStringAsync(reqString).ConfigureAwait(false));
|
||||||
var items = obj["items"] as JArray;
|
var items = obj["items"] as JArray;
|
||||||
@ -172,7 +172,7 @@ $@"🌍 **Weather for** 【{obj["target"]}】
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Lmgtfy(IUserMessage umsg, [Remainder] string ffs = null)
|
public async Task Lmgtfy(IUserMessage umsg, [Remainder] string ffs = null)
|
||||||
{
|
{
|
||||||
@ -186,7 +186,7 @@ $@"🌍 **Weather for** 【{obj["target"]}】
|
|||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Google(IUserMessage umsg, [Remainder] string terms = null)
|
public async Task Google(IUserMessage umsg, [Remainder] string terms = null)
|
||||||
{
|
{
|
||||||
@ -200,7 +200,7 @@ $@"🌍 **Weather for** 【{obj["target"]}】
|
|||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
////todo drawing
|
////todo drawing
|
||||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
//[RequireContext(ContextType.Guild)]
|
//[RequireContext(ContextType.Guild)]
|
||||||
//public async Task Hearthstone(IUserMessage umsg, [Remainder] string name = null)
|
//public async Task Hearthstone(IUserMessage umsg, [Remainder] string name = null)
|
||||||
//{
|
//{
|
||||||
@ -245,7 +245,7 @@ $@"🌍 **Weather for** 【{obj["target"]}】
|
|||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Ud(IUserMessage umsg, [Remainder] string query = null)
|
public async Task Ud(IUserMessage umsg, [Remainder] string query = null)
|
||||||
{
|
{
|
||||||
@ -279,7 +279,7 @@ $@"🌍 **Weather for** 【{obj["target"]}】
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Hashtag(IUserMessage umsg, [Remainder] string query = null)
|
public async Task Hashtag(IUserMessage umsg, [Remainder] string query = null)
|
||||||
{
|
{
|
||||||
@ -314,7 +314,7 @@ $@"🌍 **Weather for** 【{obj["target"]}】
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Catfact(IUserMessage umsg)
|
public async Task Catfact(IUserMessage umsg)
|
||||||
{
|
{
|
||||||
@ -328,7 +328,7 @@ $@"🌍 **Weather for** 【{obj["target"]}】
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Revav(IUserMessage umsg, [Remainder] string arg = null)
|
public async Task Revav(IUserMessage umsg, [Remainder] string arg = null)
|
||||||
{
|
{
|
||||||
@ -338,14 +338,14 @@ $@"🌍 **Weather for** 【{obj["target"]}】
|
|||||||
if (string.IsNullOrWhiteSpace(usrStr))
|
if (string.IsNullOrWhiteSpace(usrStr))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var usr = (await channel.Guild.GetUsersAsync()).Where(u => u.Username.ToUpperInvariant() == usrStr).FirstOrDefault();
|
var usr = channel.Guild.GetUsers().Where(u => u.Username.ToUpperInvariant() == usrStr).FirstOrDefault();
|
||||||
|
|
||||||
if (usr == null || string.IsNullOrWhiteSpace(usr.AvatarUrl))
|
if (usr == null || string.IsNullOrWhiteSpace(usr.AvatarUrl))
|
||||||
return;
|
return;
|
||||||
await channel.SendMessageAsync($"https://images.google.com/searchbyimage?image_url={usr.AvatarUrl}").ConfigureAwait(false);
|
await channel.SendMessageAsync($"https://images.google.com/searchbyimage?image_url={usr.AvatarUrl}").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Revimg(IUserMessage umsg, [Remainder] string imageLink = null)
|
public async Task Revimg(IUserMessage umsg, [Remainder] string imageLink = null)
|
||||||
{
|
{
|
||||||
@ -357,7 +357,7 @@ $@"🌍 **Weather for** 【{obj["target"]}】
|
|||||||
await channel.SendMessageAsync($"https://images.google.com/searchbyimage?image_url={imageLink}").ConfigureAwait(false);
|
await channel.SendMessageAsync($"https://images.google.com/searchbyimage?image_url={imageLink}").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Safebooru(IUserMessage umsg, [Remainder] string tag = null)
|
public async Task Safebooru(IUserMessage umsg, [Remainder] string tag = null)
|
||||||
{
|
{
|
||||||
@ -371,7 +371,7 @@ $@"🌍 **Weather for** 【{obj["target"]}】
|
|||||||
await channel.SendMessageAsync(link).ConfigureAwait(false);
|
await channel.SendMessageAsync(link).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Wiki(IUserMessage umsg, [Remainder] string query = null)
|
public async Task Wiki(IUserMessage umsg, [Remainder] string query = null)
|
||||||
{
|
{
|
||||||
@ -392,7 +392,7 @@ $@"🌍 **Weather for** 【{obj["target"]}】
|
|||||||
}
|
}
|
||||||
|
|
||||||
////todo drawing
|
////todo drawing
|
||||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
//[RequireContext(ContextType.Guild)]
|
//[RequireContext(ContextType.Guild)]
|
||||||
//public async Task Clr(IUserMessage umsg, [Remainder] string color = null)
|
//public async Task Clr(IUserMessage umsg, [Remainder] string color = null)
|
||||||
//{
|
//{
|
||||||
@ -417,7 +417,7 @@ $@"🌍 **Weather for** 【{obj["target"]}】
|
|||||||
// await channel.SendFileAsync("arg1.png", img.ToStream());
|
// await channel.SendFileAsync("arg1.png", img.ToStream());
|
||||||
//}
|
//}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Videocall(IUserMessage umsg, [Remainder] string arg = null)
|
public async Task Videocall(IUserMessage umsg, [Remainder] string arg = null)
|
||||||
{
|
{
|
||||||
@ -428,7 +428,7 @@ $@"🌍 **Weather for** 【{obj["target"]}】
|
|||||||
var allUsrs = umsg.MentionedUsers.Append(umsg.Author);
|
var allUsrs = umsg.MentionedUsers.Append(umsg.Author);
|
||||||
var allUsrsArray = allUsrs.ToArray();
|
var allUsrsArray = allUsrs.ToArray();
|
||||||
var str = allUsrsArray.Aggregate("http://appear.in/", (current, usr) => current + Uri.EscapeUriString(usr.Username[0].ToString()));
|
var str = allUsrsArray.Aggregate("http://appear.in/", (current, usr) => current + Uri.EscapeUriString(usr.Username[0].ToString()));
|
||||||
str += new Random().Next();
|
str += new NadekoRandom().Next();
|
||||||
foreach (var usr in allUsrsArray)
|
foreach (var usr in allUsrsArray)
|
||||||
{
|
{
|
||||||
await (await (usr as IGuildUser).CreateDMChannelAsync()).SendMessageAsync(str).ConfigureAwait(false);
|
await (await (usr as IGuildUser).CreateDMChannelAsync()).SendMessageAsync(str).ConfigureAwait(false);
|
||||||
@ -440,7 +440,7 @@ $@"🌍 **Weather for** 【{obj["target"]}】
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Avatar(IUserMessage umsg, [Remainder] string mention = null)
|
public async Task Avatar(IUserMessage umsg, [Remainder] string mention = null)
|
||||||
{
|
{
|
||||||
@ -457,7 +457,7 @@ $@"🌍 **Weather for** 【{obj["target"]}】
|
|||||||
|
|
||||||
public static async Task<string> GetSafebooruImageLink(string tag)
|
public static async Task<string> GetSafebooruImageLink(string tag)
|
||||||
{
|
{
|
||||||
var rng = new Random();
|
var rng = new NadekoRandom();
|
||||||
var url =
|
var url =
|
||||||
$"http://safebooru.org/index.php?page=dapi&s=post&q=index&limit=100&tags={tag.Replace(" ", "_")}";
|
$"http://safebooru.org/index.php?page=dapi&s=post&q=index&limit=100&tags={tag.Replace(" ", "_")}";
|
||||||
using (var http = new HttpClient())
|
using (var http = new HttpClient())
|
||||||
|
@ -9,14 +9,14 @@ using Discord.WebSocket;
|
|||||||
|
|
||||||
namespace NadekoBot.Modules.Translator
|
namespace NadekoBot.Modules.Translator
|
||||||
{
|
{
|
||||||
[Module("~", AppendSpace = false)]
|
[NadekoModule("Translator", "~")]
|
||||||
public class Translator : DiscordModule
|
public class Translator : DiscordModule
|
||||||
{
|
{
|
||||||
public Translator(ILocalization loc, CommandService cmds, DiscordSocketClient client) : base(loc, cmds, client)
|
public Translator(ILocalization loc, CommandService cmds, DiscordSocketClient client) : base(loc, cmds, client)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Translate(IUserMessage umsg, string langs, [Remainder] string text = null)
|
public async Task Translate(IUserMessage umsg, string langs, [Remainder] string text = null)
|
||||||
{
|
{
|
||||||
@ -44,7 +44,7 @@ namespace NadekoBot.Modules.Translator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Translangs(IUserMessage umsg)
|
public async Task Translangs(IUserMessage umsg)
|
||||||
{
|
{
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
////todo rewrite
|
////todo rewrite
|
||||||
//namespace NadekoBot.Modules.Trello
|
//namespace NadekoBot.Modules.Trello
|
||||||
//{
|
//{
|
||||||
// internal class Trello : DiscordModule
|
// public class Trello : DiscordModule
|
||||||
// {
|
// {
|
||||||
// private readonly Timer t = new Timer { Interval = 2000 };
|
// private readonly Timer t = new Timer { Interval = 2000 };
|
||||||
// public override string Prefix { get; } = NadekoBot.Config.CommandPrefixes.Trello;
|
// public override string Prefix { get; } = NadekoBot.Config.CommandPrefixes.Trello;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
|
using Discord.WebSocket;
|
||||||
using NadekoBot.Attributes;
|
using NadekoBot.Attributes;
|
||||||
using NadekoBot.Extensions;
|
using NadekoBot.Extensions;
|
||||||
using System;
|
using System;
|
||||||
@ -11,7 +12,7 @@ namespace NadekoBot.Modules.Utility
|
|||||||
{
|
{
|
||||||
partial class Utility : DiscordModule
|
partial class Utility : DiscordModule
|
||||||
{
|
{
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task ServerInfo(IUserMessage msg, string guild = null)
|
public async Task ServerInfo(IUserMessage msg, string guild = null)
|
||||||
{
|
{
|
||||||
@ -21,7 +22,7 @@ namespace NadekoBot.Modules.Utility
|
|||||||
if (guild == null)
|
if (guild == null)
|
||||||
server = channel.Guild;
|
server = channel.Guild;
|
||||||
else
|
else
|
||||||
server = (await _client.GetGuildsAsync()).Where(g => g.Name.ToUpperInvariant() == guild.ToUpperInvariant()).FirstOrDefault();
|
server = _client.GetGuilds().Where(g => g.Name.ToUpperInvariant() == guild.ToUpperInvariant()).FirstOrDefault();
|
||||||
if (server == null)
|
if (server == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -46,7 +47,7 @@ namespace NadekoBot.Modules.Utility
|
|||||||
await msg.Reply(sb.ToString()).ConfigureAwait(false);
|
await msg.Reply(sb.ToString()).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task ChannelInfo(IUserMessage msg, ITextChannel channel = null)
|
public async Task ChannelInfo(IUserMessage msg, ITextChannel channel = null)
|
||||||
{
|
{
|
||||||
@ -62,7 +63,7 @@ namespace NadekoBot.Modules.Utility
|
|||||||
await msg.Reply(toReturn).ConfigureAwait(false);
|
await msg.Reply(toReturn).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task UserInfo(IUserMessage msg, IGuildUser usr = null)
|
public async Task UserInfo(IUserMessage msg, IGuildUser usr = null)
|
||||||
{
|
{
|
||||||
|
@ -14,7 +14,7 @@ namespace NadekoBot.Modules.Utility
|
|||||||
{
|
{
|
||||||
public partial class Utility
|
public partial class Utility
|
||||||
{
|
{
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task ShowQuote(IUserMessage umsg, string keyword)
|
public async Task ShowQuote(IUserMessage umsg, string keyword)
|
||||||
{
|
{
|
||||||
@ -37,7 +37,7 @@ namespace NadekoBot.Modules.Utility
|
|||||||
await channel.SendMessageAsync("📣 " + quote.Text);
|
await channel.SendMessageAsync("📣 " + quote.Text);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task AddQuote(IUserMessage umsg, string keyword, [Remainder] string text)
|
public async Task AddQuote(IUserMessage umsg, string keyword, [Remainder] string text)
|
||||||
{
|
{
|
||||||
@ -63,7 +63,7 @@ namespace NadekoBot.Modules.Utility
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task DeleteQuote(IUserMessage umsg, string keyword)
|
public async Task DeleteQuote(IUserMessage umsg, string keyword)
|
||||||
{
|
{
|
||||||
@ -90,7 +90,7 @@ namespace NadekoBot.Modules.Utility
|
|||||||
await channel.SendMessageAsync("`Deleted a random quote.`");
|
await channel.SendMessageAsync("`Deleted a random quote.`");
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task DelAllQuotes(IUserMessage umsg, string keyword)
|
public async Task DelAllQuotes(IUserMessage umsg, string keyword)
|
||||||
{
|
{
|
||||||
|
@ -67,12 +67,7 @@ namespace NadekoBot.Modules.Utility
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ch = NadekoBot.Client.GetGuilds()
|
ch = NadekoBot.Client.GetGuild(r.ServerId)?.GetTextChannel(r.ChannelId);
|
||||||
.Where(g => g.Id == r.ServerId)
|
|
||||||
.FirstOrDefault()
|
|
||||||
.GetTextChannels()
|
|
||||||
.Where(c => c.Id == r.ChannelId)
|
|
||||||
.FirstOrDefault();
|
|
||||||
}
|
}
|
||||||
if (ch == null)
|
if (ch == null)
|
||||||
return;
|
return;
|
||||||
@ -97,7 +92,7 @@ namespace NadekoBot.Modules.Utility
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Remind(IUserMessage umsg, string meorchannel, string timeStr, [Remainder] string message)
|
public async Task Remind(IUserMessage umsg, string meorchannel, string timeStr, [Remainder] string message)
|
||||||
{
|
{
|
||||||
@ -190,7 +185,7 @@ namespace NadekoBot.Modules.Utility
|
|||||||
}
|
}
|
||||||
|
|
||||||
////todo owner only
|
////todo owner only
|
||||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
//[RequireContext(ContextType.Guild)]
|
//[RequireContext(ContextType.Guild)]
|
||||||
//public async Task RemindTemplate(IUserMessage umsg, [Remainder] string arg)
|
//public async Task RemindTemplate(IUserMessage umsg, [Remainder] string arg)
|
||||||
//{
|
//{
|
||||||
|
@ -15,7 +15,7 @@ using Discord.WebSocket;
|
|||||||
namespace NadekoBot.Modules.Utility
|
namespace NadekoBot.Modules.Utility
|
||||||
{
|
{
|
||||||
|
|
||||||
[Module(".", AppendSpace = false)]
|
[NadekoModule("Utility", ".")]
|
||||||
public partial class Utility : DiscordModule
|
public partial class Utility : DiscordModule
|
||||||
{
|
{
|
||||||
public Utility(ILocalization loc, CommandService cmds, DiscordSocketClient client) : base(loc, cmds, client)
|
public Utility(ILocalization loc, CommandService cmds, DiscordSocketClient client) : base(loc, cmds, client)
|
||||||
@ -23,7 +23,7 @@ namespace NadekoBot.Modules.Utility
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task WhosPlaying(IUserMessage umsg, [Remainder] string game = null)
|
public async Task WhosPlaying(IUserMessage umsg, [Remainder] string game = null)
|
||||||
{
|
{
|
||||||
@ -43,7 +43,7 @@ namespace NadekoBot.Modules.Utility
|
|||||||
await channel.SendMessageAsync("```xl\n" + string.Join("\n", arr.GroupBy(item => (i++) / 3).Select(ig => string.Concat(ig.Select(el => $"• {el,-35}")))) + "\n```").ConfigureAwait(false);
|
await channel.SendMessageAsync("```xl\n" + string.Join("\n", arr.GroupBy(item => (i++) / 3).Select(ig => string.Concat(ig.Select(el => $"• {el,-35}")))) + "\n```").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task InRole(IUserMessage umsg, [Remainder] string roles = null)
|
public async Task InRole(IUserMessage umsg, [Remainder] string roles = null)
|
||||||
{
|
{
|
||||||
@ -76,7 +76,7 @@ namespace NadekoBot.Modules.Utility
|
|||||||
await channel.SendMessageAsync(send).ConfigureAwait(false);
|
await channel.SendMessageAsync(send).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task CheckMyPerms(IUserMessage msg)
|
public async Task CheckMyPerms(IUserMessage msg)
|
||||||
{
|
{
|
||||||
@ -93,7 +93,7 @@ namespace NadekoBot.Modules.Utility
|
|||||||
await msg.Reply(builder.ToString());
|
await msg.Reply(builder.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task UserId(IUserMessage msg, IGuildUser target = null)
|
public async Task UserId(IUserMessage msg, IGuildUser target = null)
|
||||||
{
|
{
|
||||||
@ -101,20 +101,20 @@ namespace NadekoBot.Modules.Utility
|
|||||||
await msg.Reply($"Id of the user { usr.Username } is { usr.Id })").ConfigureAwait(false);
|
await msg.Reply($"Id of the user { usr.Username } is { usr.Id })").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
public async Task ChannelId(IUserMessage msg)
|
public async Task ChannelId(IUserMessage msg)
|
||||||
{
|
{
|
||||||
await msg.Reply($"This Channel's ID is {msg.Channel.Id}").ConfigureAwait(false);
|
await msg.Reply($"This Channel's ID is {msg.Channel.Id}").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task ServerId(IUserMessage msg)
|
public async Task ServerId(IUserMessage msg)
|
||||||
{
|
{
|
||||||
await msg.Reply($"This server's ID is {(msg.Channel as ITextChannel).Guild.Id}").ConfigureAwait(false);
|
await msg.Reply($"This server's ID is {(msg.Channel as ITextChannel).Guild.Id}").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Roles(IUserMessage msg, IGuildUser target = null)
|
public async Task Roles(IUserMessage msg, IGuildUser target = null)
|
||||||
{
|
{
|
||||||
@ -129,7 +129,7 @@ namespace NadekoBot.Modules.Utility
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task ChannelTopic(IUserMessage umsg)
|
public async Task ChannelTopic(IUserMessage umsg)
|
||||||
{
|
{
|
||||||
@ -142,7 +142,7 @@ namespace NadekoBot.Modules.Utility
|
|||||||
await channel.SendMessageAsync("`Topic:` " + topic);
|
await channel.SendMessageAsync("`Topic:` " + topic);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Stats(IUserMessage umsg)
|
public async Task Stats(IUserMessage umsg)
|
||||||
{
|
{
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
using NadekoBot.Services;
|
using NadekoBot.Services;
|
||||||
|
using NadekoBot.Services.Database;
|
||||||
using NadekoBot.Services.Impl;
|
using NadekoBot.Services.Impl;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NLog.Config;
|
using NLog.Config;
|
||||||
@ -11,6 +12,7 @@ using System.Diagnostics;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using NLog.Fluent;
|
||||||
|
|
||||||
namespace NadekoBot
|
namespace NadekoBot
|
||||||
{
|
{
|
||||||
@ -19,22 +21,26 @@ namespace NadekoBot
|
|||||||
private Logger _log;
|
private Logger _log;
|
||||||
|
|
||||||
public static CommandService Commands { get; private set; }
|
public static CommandService Commands { get; private set; }
|
||||||
|
public static CommandHandler CommandHandler { get; private set; }
|
||||||
public static DiscordSocketClient Client { get; private set; }
|
public static DiscordSocketClient Client { get; private set; }
|
||||||
public static Localization Localizer { get; private set; }
|
public static Localization Localizer { get; private set; }
|
||||||
public static BotCredentials Credentials { get; private set; }
|
public static BotCredentials Credentials { get; private set; }
|
||||||
|
|
||||||
public static GoogleApiService Google { get; set; }
|
public static GoogleApiService Google { get; private set; }
|
||||||
public static StatsService Stats { get; private set; }
|
public static StatsService Stats { get; private set; }
|
||||||
|
|
||||||
public async Task RunAsync(string[] args)
|
public async Task RunAsync(string[] args)
|
||||||
{
|
{
|
||||||
SetupLogger();
|
SetupLogger();
|
||||||
|
_log = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
|
_log.Info("Starting NadekoBot v" + typeof(NadekoBot).GetTypeInfo().Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion);
|
||||||
|
|
||||||
//create client
|
//create client
|
||||||
Client = new DiscordSocketClient(new DiscordSocketConfig
|
Client = new DiscordSocketClient(new DiscordSocketConfig
|
||||||
{
|
{
|
||||||
AudioMode = Discord.Audio.AudioMode.Outgoing,
|
AudioMode = Discord.Audio.AudioMode.Outgoing,
|
||||||
LargeThreshold = 200,
|
MessageCacheSize = 10,
|
||||||
LogLevel = LogSeverity.Warning,
|
LogLevel = LogSeverity.Warning,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -43,8 +49,14 @@ namespace NadekoBot
|
|||||||
Commands = new CommandService();
|
Commands = new CommandService();
|
||||||
Localizer = new Localization();
|
Localizer = new Localization();
|
||||||
Google = new GoogleApiService();
|
Google = new GoogleApiService();
|
||||||
Stats = new StatsService(Client);
|
CommandHandler = new CommandHandler(Client, Commands);
|
||||||
_log = LogManager.GetCurrentClassLogger();
|
Stats = new StatsService(Client, CommandHandler);
|
||||||
|
|
||||||
|
//init db
|
||||||
|
using (var context = DbHandler.Instance.GetDbContext())
|
||||||
|
{
|
||||||
|
context.EnsureSeedData();
|
||||||
|
}
|
||||||
|
|
||||||
//setup DI
|
//setup DI
|
||||||
var depMap = new DependencyMap();
|
var depMap = new DependencyMap();
|
||||||
@ -54,16 +66,16 @@ namespace NadekoBot
|
|||||||
depMap.Add<IGoogleApiService>(Google);
|
depMap.Add<IGoogleApiService>(Google);
|
||||||
|
|
||||||
//connect
|
//connect
|
||||||
await Client.LoginAsync(TokenType.Bot, Credentials.Token);
|
await Client.LoginAsync(TokenType.Bot, Credentials.Token).ConfigureAwait(false);
|
||||||
await Client.ConnectAsync();
|
await Client.ConnectAsync().ConfigureAwait(false);
|
||||||
|
await Client.DownloadAllUsersAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
_log.Info("Connected");
|
_log.Info("Connected");
|
||||||
|
|
||||||
//load commands
|
//load commands
|
||||||
await Commands.LoadAssembly(Assembly.GetEntryAssembly(), depMap);
|
await Commands.LoadAssembly(Assembly.GetEntryAssembly(), depMap).ConfigureAwait(false);
|
||||||
Client.MessageReceived += Client_MessageReceived;
|
|
||||||
|
|
||||||
Console.WriteLine(await Stats.Print());
|
Console.WriteLine(await Stats.Print().ConfigureAwait(false));
|
||||||
|
|
||||||
await Task.Delay(-1);
|
await Task.Delay(-1);
|
||||||
}
|
}
|
||||||
@ -83,57 +95,10 @@ namespace NadekoBot
|
|||||||
|
|
||||||
LogManager.Configuration = logConfig;
|
LogManager.Configuration = logConfig;
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex)
|
||||||
|
{
|
||||||
Console.WriteLine(ex);
|
Console.WriteLine(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Task Client_MessageReceived(IMessage umsg)
|
|
||||||
{
|
|
||||||
var usrMsg = umsg as IUserMessage;
|
|
||||||
if (usrMsg == null)
|
|
||||||
return Task.CompletedTask;
|
|
||||||
var throwaway = Task.Run(async () =>
|
|
||||||
{
|
|
||||||
var sw = new Stopwatch();
|
|
||||||
sw.Start();
|
|
||||||
var t = await Commands.Execute(usrMsg, usrMsg.Content);
|
|
||||||
sw.Stop();
|
|
||||||
var channel = (umsg.Channel as ITextChannel);
|
|
||||||
if (t.IsSuccess)
|
|
||||||
{
|
|
||||||
|
|
||||||
_log.Info("Command Executed after {4}s\n\t" +
|
|
||||||
"User: {0}\n\t" +
|
|
||||||
"Server: {1}\n\t" +
|
|
||||||
"Channel: {2}\n\t" +
|
|
||||||
"Message: {3}",
|
|
||||||
umsg.Author + " [" + umsg.Author.Id + "]", // {0}
|
|
||||||
(channel == null ? "PRIVATE" : channel.Guild.Name + " [" + channel.Guild.Id + "]"), // {1}
|
|
||||||
(channel == null ? "PRIVATE" : channel.Name + " [" + channel.Id + "]"), //{2}
|
|
||||||
umsg.Content, // {3}
|
|
||||||
sw.Elapsed.TotalSeconds // {4}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else if (!t.IsSuccess && t.Error != CommandError.UnknownCommand)
|
|
||||||
{
|
|
||||||
_log.Warn("Command Errored after {5}s\n\t" +
|
|
||||||
"User: {0}\n\t" +
|
|
||||||
"Server: {1}\n\t" +
|
|
||||||
"Channel: {2}\n\t" +
|
|
||||||
"Message: {3}\n\t" +
|
|
||||||
"Error: {4}",
|
|
||||||
umsg.Author + " [" + umsg.Author.Id + "]", // {0}
|
|
||||||
(channel == null ? "PRIVATE" : channel.Guild.Name + " [" + channel.Guild.Id + "]"), // {1}
|
|
||||||
(channel == null ? "PRIVATE" : channel.Name + " [" + channel.Id + "]"), //{2}
|
|
||||||
umsg.Content,// {3}
|
|
||||||
t.ErrorReason, // {4}
|
|
||||||
sw.Elapsed.TotalSeconds //{5}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
{
|
{
|
||||||
public class Program
|
public class Program
|
||||||
{
|
{
|
||||||
public static void Main(string[] args) => new NadekoBot().RunAsync(args).GetAwaiter().GetResult();
|
public static void Main(string[] args) =>
|
||||||
|
new NadekoBot().RunAsync(args).GetAwaiter().GetResult();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ using System.Runtime.InteropServices;
|
|||||||
[assembly: AssemblyCompany("")]
|
[assembly: AssemblyCompany("")]
|
||||||
[assembly: AssemblyProduct("NadekoBot")]
|
[assembly: AssemblyProduct("NadekoBot")]
|
||||||
[assembly: AssemblyTrademark("")]
|
[assembly: AssemblyTrademark("")]
|
||||||
|
[assembly: AssemblyInformationalVersion("1.0-alpha")]
|
||||||
|
|
||||||
// Setting ComVisible to false makes the types in this assembly not visible
|
// Setting ComVisible to false makes the types in this assembly not visible
|
||||||
// to COM components. If you need to access a type in this assembly from
|
// to COM components. If you need to access a type in this assembly from
|
||||||
|
424
src/NadekoBot/Resources/CommandStrings.Designer.cs
generated
424
src/NadekoBot/Resources/CommandStrings.Designer.cs
generated
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -28,7 +28,7 @@ namespace NadekoBot.Resources {
|
|||||||
|
|
||||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||||
|
|
||||||
internal ResponseStrings() {
|
public ResponseStrings() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
93
src/NadekoBot/Services/CommandHandler.cs
Normal file
93
src/NadekoBot/Services/CommandHandler.cs
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
using Discord.WebSocket;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Discord;
|
||||||
|
using NLog;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using Discord.Commands;
|
||||||
|
|
||||||
|
namespace NadekoBot.Services
|
||||||
|
{
|
||||||
|
public class CommandHandler
|
||||||
|
{
|
||||||
|
private DiscordSocketClient _client;
|
||||||
|
private CommandService _commandService;
|
||||||
|
private Logger _log;
|
||||||
|
|
||||||
|
public event EventHandler<CommandExecutedEventArgs> CommandExecuted = delegate { };
|
||||||
|
|
||||||
|
public CommandHandler(DiscordSocketClient client, CommandService commandService)
|
||||||
|
{
|
||||||
|
_client = client;
|
||||||
|
_commandService = commandService;
|
||||||
|
_log = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
|
_client.MessageReceived += MessageReceivedHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Task MessageReceivedHandler(IMessage msg)
|
||||||
|
{
|
||||||
|
var usrMsg = msg as IUserMessage;
|
||||||
|
if (usrMsg == null)
|
||||||
|
return Task.CompletedTask;
|
||||||
|
var throwaway = Task.Run(async () =>
|
||||||
|
{
|
||||||
|
var sw = new Stopwatch();
|
||||||
|
sw.Start();
|
||||||
|
var t = await _commandService.Execute(usrMsg, usrMsg.Content, MultiMatchHandling.Best);
|
||||||
|
var command = t.Item1;
|
||||||
|
var result = t.Item2;
|
||||||
|
sw.Stop();
|
||||||
|
var channel = (usrMsg.Channel as ITextChannel);
|
||||||
|
if (result.IsSuccess)
|
||||||
|
{
|
||||||
|
CommandExecuted(this, new CommandExecutedEventArgs(usrMsg, command));
|
||||||
|
_log.Info("Command Executed after {4}s\n\t" +
|
||||||
|
"User: {0}\n\t" +
|
||||||
|
"Server: {1}\n\t" +
|
||||||
|
"Channel: {2}\n\t" +
|
||||||
|
"Message: {3}",
|
||||||
|
usrMsg.Author + " [" + usrMsg.Author.Id + "]", // {0}
|
||||||
|
(channel == null ? "PRIVATE" : channel.Guild.Name + " [" + channel.Guild.Id + "]"), // {1}
|
||||||
|
(channel == null ? "PRIVATE" : channel.Name + " [" + channel.Id + "]"), // {2}
|
||||||
|
usrMsg.Content, // {3}
|
||||||
|
sw.Elapsed.TotalSeconds // {4}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else if (!result.IsSuccess && result.Error != CommandError.UnknownCommand)
|
||||||
|
{
|
||||||
|
_log.Warn("Command Errored after {5}s\n\t" +
|
||||||
|
"User: {0}\n\t" +
|
||||||
|
"Server: {1}\n\t" +
|
||||||
|
"Channel: {2}\n\t" +
|
||||||
|
"Message: {3}\n\t" +
|
||||||
|
"Error: {4}",
|
||||||
|
usrMsg.Author + " [" + usrMsg.Author.Id + "]", // {0}
|
||||||
|
(channel == null ? "PRIVATE" : channel.Guild.Name + " [" + channel.Guild.Id + "]"), // {1}
|
||||||
|
(channel == null ? "PRIVATE" : channel.Name + " [" + channel.Id + "]"), // {2}
|
||||||
|
usrMsg.Content,// {3}
|
||||||
|
result.ErrorReason, // {4}
|
||||||
|
sw.Elapsed.TotalSeconds // {5}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class CommandExecutedEventArgs
|
||||||
|
{
|
||||||
|
public Command Command { get; }
|
||||||
|
public IUserMessage Message { get; }
|
||||||
|
|
||||||
|
public CommandExecutedEventArgs(IUserMessage msg, Command cmd)
|
||||||
|
{
|
||||||
|
Message = msg;
|
||||||
|
Command = cmd;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
51
src/NadekoBot/Services/CurrencyHandler.cs
Normal file
51
src/NadekoBot/Services/CurrencyHandler.cs
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Discord;
|
||||||
|
using NadekoBot.Services.Database;
|
||||||
|
using NadekoBot.Extensions;
|
||||||
|
using NadekoBot.Modules.Gambling;
|
||||||
|
|
||||||
|
namespace NadekoBot.Services
|
||||||
|
{
|
||||||
|
public static class CurrencyHandler
|
||||||
|
{
|
||||||
|
public static async Task<bool> RemoveCurrencyAsync(IGuildUser author, string reason, long amount, bool sendMessage)
|
||||||
|
{
|
||||||
|
if (amount < 0)
|
||||||
|
throw new ArgumentNullException(nameof(amount));
|
||||||
|
|
||||||
|
|
||||||
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
|
{
|
||||||
|
var success = uow.Currency.TryUpdateState(author.Id, -amount);
|
||||||
|
if (!success)
|
||||||
|
return false;
|
||||||
|
await uow.CompleteAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sendMessage)
|
||||||
|
try { await author.SendMessageAsync($"`You lost:` {amount} {Gambling.CurrencySign}\n`Reason:` {reason}").ConfigureAwait(false); } catch { }
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task AddCurrencyAsync(IGuildUser author, string reason, long amount, bool sendMessage)
|
||||||
|
{
|
||||||
|
if (amount < 0)
|
||||||
|
throw new ArgumentNullException(nameof(amount));
|
||||||
|
|
||||||
|
|
||||||
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
|
{
|
||||||
|
uow.Currency.TryUpdateState(author.Id, amount);
|
||||||
|
await uow.CompleteAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sendMessage)
|
||||||
|
await author.SendMessageAsync($"`You received:` {amount} {Gambling.CurrencySign}\n`Reason:` {reason}").ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -16,6 +16,8 @@ namespace NadekoBot.Services.Database
|
|||||||
IReminderRepository Reminders { get; }
|
IReminderRepository Reminders { get; }
|
||||||
ISelfAssignedRolesRepository SelfAssignedRoles { get; }
|
ISelfAssignedRolesRepository SelfAssignedRoles { get; }
|
||||||
IBotConfigRepository BotConfig { get; }
|
IBotConfigRepository BotConfig { get; }
|
||||||
|
IRepeaterRepository Repeaters { get; }
|
||||||
|
IUnitConverterRepository ConverterUnits { get; }
|
||||||
|
|
||||||
int Complete();
|
int Complete();
|
||||||
Task<int> CompleteAsync();
|
Task<int> CompleteAsync();
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -15,21 +16,10 @@ namespace NadekoBot.Services.Database.Models
|
|||||||
public bool ForwardMessages { get; set; } = true;
|
public bool ForwardMessages { get; set; } = true;
|
||||||
public bool ForwardToAllOwners { get; set; } = true;
|
public bool ForwardToAllOwners { get; set; } = true;
|
||||||
|
|
||||||
public List<ModulePrefix> ModulePrefixes { get; set; } = new List<ModulePrefix>()
|
public float CurrencyGenerationChance { get; set; } = 0.02f;
|
||||||
{
|
public int CurrencyGenerationCooldown { get; set; } = 10;
|
||||||
new ModulePrefix() { ModuleName="Administration", Prefix="." },
|
|
||||||
new ModulePrefix() { ModuleName="Searches", Prefix="~" },
|
public List<ModulePrefix> ModulePrefixes { get; set; } = new List<ModulePrefix>();
|
||||||
new ModulePrefix() { ModuleName="NSFW", Prefix="~" },
|
|
||||||
new ModulePrefix() { ModuleName="ClashOfClans", Prefix="," },
|
|
||||||
new ModulePrefix() { ModuleName="Help", Prefix="-" },
|
|
||||||
new ModulePrefix() { ModuleName="Music", Prefix="!!" },
|
|
||||||
new ModulePrefix() { ModuleName="Trello", Prefix="trello" },
|
|
||||||
new ModulePrefix() { ModuleName="Games", Prefix=">" },
|
|
||||||
new ModulePrefix() { ModuleName="Gambling", Prefix="$" },
|
|
||||||
new ModulePrefix() { ModuleName="Permissions", Prefix=";" },
|
|
||||||
new ModulePrefix() { ModuleName="Pokemon", Prefix=">" },
|
|
||||||
new ModulePrefix() { ModuleName="Utility", Prefix="." }
|
|
||||||
};
|
|
||||||
|
|
||||||
public List<PlayingStatus> RotatingStatusMessages { get; set; } = new List<PlayingStatus>();
|
public List<PlayingStatus> RotatingStatusMessages { get; set; } = new List<PlayingStatus>();
|
||||||
|
|
||||||
@ -41,43 +31,8 @@ namespace NadekoBot.Services.Database.Models
|
|||||||
public string CurrencyName { get; set; } = "Nadeko Flower";
|
public string CurrencyName { get; set; } = "Nadeko Flower";
|
||||||
public string CurrencyPluralName { get; set; } = "Nadeko Flowers";
|
public string CurrencyPluralName { get; set; } = "Nadeko Flowers";
|
||||||
|
|
||||||
public List<EightBallResponse> EightBallResponses { get; set; } = new List<EightBallResponse>
|
public List<EightBallResponse> EightBallResponses { get; set; } = new List<EightBallResponse>();
|
||||||
{
|
public List<RaceAnimal> RaceAnimals { get; set; } = new List<RaceAnimal>();
|
||||||
new EightBallResponse() { Text = "Most definitely yes" },
|
|
||||||
new EightBallResponse() { Text = "For sure" },
|
|
||||||
new EightBallResponse() { Text = "Totally!" },
|
|
||||||
new EightBallResponse() { Text = "As I see it, yes" },
|
|
||||||
new EightBallResponse() { Text = "My sources say yes" },
|
|
||||||
new EightBallResponse() { Text = "Yes" },
|
|
||||||
new EightBallResponse() { Text = "Most likely" },
|
|
||||||
new EightBallResponse() { Text = "Perhaps" },
|
|
||||||
new EightBallResponse() { Text = "Maybe" },
|
|
||||||
new EightBallResponse() { Text = "Not sure" },
|
|
||||||
new EightBallResponse() { Text = "It is uncertain" },
|
|
||||||
new EightBallResponse() { Text = "Ask me again later" },
|
|
||||||
new EightBallResponse() { Text = "Don't count on it" },
|
|
||||||
new EightBallResponse() { Text = "Probably not" },
|
|
||||||
new EightBallResponse() { Text = "Very doubtful" },
|
|
||||||
new EightBallResponse() { Text = "Most likely no" },
|
|
||||||
new EightBallResponse() { Text = "Nope" },
|
|
||||||
new EightBallResponse() { Text = "No" },
|
|
||||||
new EightBallResponse() { Text = "My sources say no" },
|
|
||||||
new EightBallResponse() { Text = "Dont even think about it" },
|
|
||||||
new EightBallResponse() { Text = "Definitely no" },
|
|
||||||
new EightBallResponse() { Text = "NO - It may cause disease contraction" }
|
|
||||||
};
|
|
||||||
|
|
||||||
public List<RaceAnimal> RaceAnimals { get; set; } = new List<RaceAnimal>
|
|
||||||
{
|
|
||||||
new RaceAnimal { Icon = "🐼", Name = "Panda" },
|
|
||||||
new RaceAnimal { Icon = "🐻", Name = "Bear" },
|
|
||||||
new RaceAnimal { Icon = "🐧", Name = "Pengu" },
|
|
||||||
new RaceAnimal { Icon = "🐨", Name = "Koala" },
|
|
||||||
new RaceAnimal { Icon = "🐬", Name = "Dolphin" },
|
|
||||||
new RaceAnimal { Icon = "🐞", Name = "Ladybird" },
|
|
||||||
new RaceAnimal { Icon = "🦀", Name = "Crab" },
|
|
||||||
new RaceAnimal { Icon = "🦄", Name = "Unicorn" }
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PlayingStatus :DbEntity
|
public class PlayingStatus :DbEntity
|
||||||
@ -99,17 +54,59 @@ namespace NadekoBot.Services.Database.Models
|
|||||||
public class EightBallResponse : DbEntity
|
public class EightBallResponse : DbEntity
|
||||||
{
|
{
|
||||||
public string Text { get; set; }
|
public string Text { get; set; }
|
||||||
|
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return Text.GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object obj)
|
||||||
|
{
|
||||||
|
if (!(obj is EightBallResponse))
|
||||||
|
return base.Equals(obj);
|
||||||
|
|
||||||
|
return ((EightBallResponse)obj).Text == Text;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class RaceAnimal : DbEntity
|
public class RaceAnimal : DbEntity
|
||||||
{
|
{
|
||||||
public string Icon { get; set; }
|
public string Icon { get; set; }
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return Icon.GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object obj)
|
||||||
|
{
|
||||||
|
if (!(obj is RaceAnimal))
|
||||||
|
return base.Equals(obj);
|
||||||
|
|
||||||
|
return ((RaceAnimal)obj).Icon == Icon;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ModulePrefix : DbEntity
|
public class ModulePrefix : DbEntity
|
||||||
{
|
{
|
||||||
public string ModuleName { get; set; }
|
public string ModuleName { get; set; }
|
||||||
public string Prefix { get; set; }
|
public string Prefix { get; set; }
|
||||||
|
|
||||||
|
public int BotConfigId { get; set; } = 1;
|
||||||
|
public BotConfig BotConfig { get; set; }
|
||||||
|
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return ModuleName.GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object obj)
|
||||||
|
{
|
||||||
|
if(!(obj is ModulePrefix))
|
||||||
|
return base.Equals(obj);
|
||||||
|
|
||||||
|
return ((ModulePrefix)obj).ModuleName == ModuleName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ namespace NadekoBot.Services.Database.Models
|
|||||||
public ulong ChannelId { get; set; }
|
public ulong ChannelId { get; set; }
|
||||||
|
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
public ITextChannel Channel { get; internal set; }
|
public ITextChannel Channel { get; set; }
|
||||||
|
|
||||||
public List<ClashCaller> Bases { get; set; }
|
public List<ClashCaller> Bases { get; set; }
|
||||||
}
|
}
|
||||||
|
38
src/NadekoBot/Services/Database/Models/ConvertUnit.cs
Normal file
38
src/NadekoBot/Services/Database/Models/ConvertUnit.cs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NadekoBot.Services.Database.Models
|
||||||
|
{
|
||||||
|
public class ConvertUnit : DbEntity
|
||||||
|
{
|
||||||
|
public ConvertUnit() { }
|
||||||
|
[NotMapped]
|
||||||
|
private string[] _triggersValue;
|
||||||
|
[NotMapped]
|
||||||
|
public string[] Triggers
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _triggersValue ?? (_triggersValue = InternalTrigger.Split('|'));
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_triggersValue = value;
|
||||||
|
InternalTrigger = string.Join("|", _triggersValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//protected or private?
|
||||||
|
/// <summary>
|
||||||
|
/// DO NOT CALL THIS
|
||||||
|
/// </summary>
|
||||||
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||||
|
public string InternalTrigger { get; set; }
|
||||||
|
public string UnitType { get; set; }
|
||||||
|
public decimal Modifier { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
14
src/NadekoBot/Services/Database/Models/Currency.cs
Normal file
14
src/NadekoBot/Services/Database/Models/Currency.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NadekoBot.Services.Database.Models
|
||||||
|
{
|
||||||
|
public class Currency : DbEntity
|
||||||
|
{
|
||||||
|
public ulong UserId { get; set; }
|
||||||
|
public long Amount { get; set; }
|
||||||
|
}
|
||||||
|
}
|
22
src/NadekoBot/Services/Database/Models/FollowedStream.cs
Normal file
22
src/NadekoBot/Services/Database/Models/FollowedStream.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NadekoBot.Services.Database.Models
|
||||||
|
{
|
||||||
|
public class FollowedStream : DbEntity
|
||||||
|
{
|
||||||
|
public ulong ChannelId { get; set; }
|
||||||
|
public string Username { get; set; }
|
||||||
|
public FollowedStreamType Type { get; set; }
|
||||||
|
public bool LastStatus { get; set; }
|
||||||
|
public ulong GuildId { get; set; }
|
||||||
|
|
||||||
|
public enum FollowedStreamType
|
||||||
|
{
|
||||||
|
Twitch, Hitbox, Beam
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -28,8 +28,18 @@ namespace NadekoBot.Services.Database.Models
|
|||||||
public bool SendChannelByeMessage { get; set; }
|
public bool SendChannelByeMessage { get; set; }
|
||||||
public string ChannelByeMessageText { get; set; } = "%user% has left!";
|
public string ChannelByeMessageText { get; set; } = "%user% has left!";
|
||||||
|
|
||||||
|
public LogSetting LogSetting { get; set; } = new LogSetting();
|
||||||
|
|
||||||
//self assignable roles
|
//self assignable roles
|
||||||
public bool ExclusiveSelfAssignedRoles { get; set; }
|
public bool ExclusiveSelfAssignedRoles { get; set; }
|
||||||
public bool AutoDeleteSelfAssignedRoleMessages { get; set; }
|
public bool AutoDeleteSelfAssignedRoleMessages { get; set; }
|
||||||
|
public float DefaultMusicVolume { get; set; } = 1.0f;
|
||||||
|
public bool VoicePlusTextEnabled { get; set; }
|
||||||
|
|
||||||
|
//stream notifications
|
||||||
|
public List<FollowedStream> FollowedStreams { get; set; } = new List<FollowedStream>();
|
||||||
|
|
||||||
|
//currencyGeneration
|
||||||
|
public ulong? GenerateCurrencyChannelId { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
14
src/NadekoBot/Services/Database/Models/IgnoredLogChannel.cs
Normal file
14
src/NadekoBot/Services/Database/Models/IgnoredLogChannel.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NadekoBot.Services.Database.Models
|
||||||
|
{
|
||||||
|
public class IgnoredLogChannel : DbEntity
|
||||||
|
{
|
||||||
|
public LogSetting LogSetting { get; set; }
|
||||||
|
public ulong ChannelId { get; set; }
|
||||||
|
}
|
||||||
|
}
|
39
src/NadekoBot/Services/Database/Models/LogSetting.cs
Normal file
39
src/NadekoBot/Services/Database/Models/LogSetting.cs
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NadekoBot.Services.Database.Models
|
||||||
|
{
|
||||||
|
public class LogSetting : DbEntity
|
||||||
|
{
|
||||||
|
public bool IsLogging { get; set; }
|
||||||
|
public ulong ChannelId { get; set; }
|
||||||
|
public HashSet<IgnoredLogChannel> IgnoredChannels { get; set; }
|
||||||
|
|
||||||
|
public bool MessageReceived { get; set; } = true;
|
||||||
|
public bool MessageUpdated { get; set; } = true;
|
||||||
|
public bool MessageDeleted { get; set; } = true;
|
||||||
|
|
||||||
|
public bool UserJoined { get; set; } = true;
|
||||||
|
public bool UserLeft { get; set; } = true;
|
||||||
|
public bool UserBanned { get; set; } = true;
|
||||||
|
public bool UserUnbanned { get; set; } = true;
|
||||||
|
public bool UserUpdated { get; set; } = true;
|
||||||
|
|
||||||
|
public bool ChannelCreated { get; set; } = true;
|
||||||
|
public bool ChannelDestroyed { get; set; } = true;
|
||||||
|
public bool ChannelUpdated { get; set; } = true;
|
||||||
|
|
||||||
|
//userpresence
|
||||||
|
public bool LogUserPresence { get; set; } = false;
|
||||||
|
public ulong UserPresenceChannelId { get; set; }
|
||||||
|
|
||||||
|
//voicepresence
|
||||||
|
public bool LogVoicePresence { get; set; } = false;
|
||||||
|
public ulong VoicePresenceChannelId { get; set; }
|
||||||
|
public HashSet<IgnoredVoicePresenceChannel> IgnoredVoicePresenceChannelIds { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
16
src/NadekoBot/Services/Database/Models/Repeater.cs
Normal file
16
src/NadekoBot/Services/Database/Models/Repeater.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NadekoBot.Services.Database.Models
|
||||||
|
{
|
||||||
|
public class Repeater :DbEntity
|
||||||
|
{
|
||||||
|
public ulong GuildId { get; set; }
|
||||||
|
public ulong ChannelId { get; set; }
|
||||||
|
public string Message { get; set; }
|
||||||
|
public TimeSpan Interval { get; set; }
|
||||||
|
}
|
||||||
|
}
|
14
src/NadekoBot/Services/Database/Models/TypingArticle.cs
Normal file
14
src/NadekoBot/Services/Database/Models/TypingArticle.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NadekoBot.Services.Database.Models
|
||||||
|
{
|
||||||
|
public class TypingArticle : DbEntity
|
||||||
|
{
|
||||||
|
public string Author { get; set; }
|
||||||
|
public string Text { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NadekoBot.Services.Database.Models
|
||||||
|
{
|
||||||
|
public class IgnoredVoicePresenceChannel : DbEntity
|
||||||
|
{
|
||||||
|
public LogSetting LogSetting { get; set; }
|
||||||
|
public ulong ChannelId { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -18,6 +18,90 @@ namespace NadekoBot.Services.Database
|
|||||||
public DbSet<Reminder> Reminders { get; set; }
|
public DbSet<Reminder> Reminders { get; set; }
|
||||||
public DbSet<SelfAssignedRole> SelfAssignableRoles { get; set; }
|
public DbSet<SelfAssignedRole> SelfAssignableRoles { get; set; }
|
||||||
public DbSet<BotConfig> BotConfig { get; set; }
|
public DbSet<BotConfig> BotConfig { get; set; }
|
||||||
|
public DbSet<Repeater> Repeaters { get; set; }
|
||||||
|
public DbSet<Currency> Currency { get; set; }
|
||||||
|
public DbSet<ConvertUnit> ConversionUnits { get; set; }
|
||||||
|
public DbSet<TypingArticle> TypingArticles { get; set; }
|
||||||
|
|
||||||
|
//logging
|
||||||
|
public DbSet<LogSetting> LogSettings { get; set; }
|
||||||
|
public DbSet<IgnoredLogChannel> IgnoredLogChannels { get; set; }
|
||||||
|
public DbSet<IgnoredVoicePresenceChannel> IgnoredVoicePresenceCHannels { get; set; }
|
||||||
|
|
||||||
|
//orphans xD
|
||||||
|
public DbSet<EightBallResponse> EightBallResponses { get; set; }
|
||||||
|
public DbSet<RaceAnimal> RaceAnimals { get; set; }
|
||||||
|
public DbSet<ModulePrefix> ModulePrefixes { get; set; }
|
||||||
|
|
||||||
|
public void EnsureSeedData()
|
||||||
|
{
|
||||||
|
if (!BotConfig.Any())
|
||||||
|
{
|
||||||
|
var bc = new BotConfig();
|
||||||
|
|
||||||
|
bc.ModulePrefixes.AddRange(new HashSet<ModulePrefix>()
|
||||||
|
{
|
||||||
|
new ModulePrefix() { ModuleName = "Administration", Prefix = "." },
|
||||||
|
new ModulePrefix() { ModuleName = "Searches", Prefix = "~" },
|
||||||
|
new ModulePrefix() { ModuleName = "Translator", Prefix = "~" },
|
||||||
|
new ModulePrefix() { ModuleName = "NSFW", Prefix = "~" },
|
||||||
|
new ModulePrefix() { ModuleName = "ClashOfClans", Prefix = "," },
|
||||||
|
new ModulePrefix() { ModuleName = "Help", Prefix = "-" },
|
||||||
|
new ModulePrefix() { ModuleName = "Music", Prefix = "!!" },
|
||||||
|
new ModulePrefix() { ModuleName = "Trello", Prefix = "trello" },
|
||||||
|
new ModulePrefix() { ModuleName = "Games", Prefix = ">" },
|
||||||
|
new ModulePrefix() { ModuleName = "Gambling", Prefix = "$" },
|
||||||
|
new ModulePrefix() { ModuleName = "Permissions", Prefix = ";" },
|
||||||
|
new ModulePrefix() { ModuleName = "Pokemon", Prefix = ">" },
|
||||||
|
new ModulePrefix() { ModuleName = "Utility", Prefix = "." }
|
||||||
|
});
|
||||||
|
bc.RaceAnimals.AddRange(new HashSet<RaceAnimal>
|
||||||
|
{
|
||||||
|
new RaceAnimal { Icon = "🐼", Name = "Panda" },
|
||||||
|
new RaceAnimal { Icon = "🐻", Name = "Bear" },
|
||||||
|
new RaceAnimal { Icon = "🐧", Name = "Pengu" },
|
||||||
|
new RaceAnimal { Icon = "🐨", Name = "Koala" },
|
||||||
|
new RaceAnimal { Icon = "🐬", Name = "Dolphin" },
|
||||||
|
new RaceAnimal { Icon = "🐞", Name = "Ladybird" },
|
||||||
|
new RaceAnimal { Icon = "🦀", Name = "Crab" },
|
||||||
|
new RaceAnimal { Icon = "🦄", Name = "Unicorn" }
|
||||||
|
});
|
||||||
|
bc.EightBallResponses.AddRange(new HashSet<EightBallResponse>
|
||||||
|
{
|
||||||
|
new EightBallResponse() { Text = "Most definitely yes" },
|
||||||
|
new EightBallResponse() { Text = "For sure" },
|
||||||
|
new EightBallResponse() { Text = "Totally!" },
|
||||||
|
new EightBallResponse() { Text = "Of course!" },
|
||||||
|
new EightBallResponse() { Text = "As I see it, yes" },
|
||||||
|
new EightBallResponse() { Text = "My sources say yes" },
|
||||||
|
new EightBallResponse() { Text = "Yes" },
|
||||||
|
new EightBallResponse() { Text = "Most likely" },
|
||||||
|
new EightBallResponse() { Text = "Perhaps" },
|
||||||
|
new EightBallResponse() { Text = "Maybe" },
|
||||||
|
new EightBallResponse() { Text = "Not sure" },
|
||||||
|
new EightBallResponse() { Text = "It is uncertain" },
|
||||||
|
new EightBallResponse() { Text = "Ask me again later" },
|
||||||
|
new EightBallResponse() { Text = "Don't count on it" },
|
||||||
|
new EightBallResponse() { Text = "Probably not" },
|
||||||
|
new EightBallResponse() { Text = "Very doubtful" },
|
||||||
|
new EightBallResponse() { Text = "Most likely no" },
|
||||||
|
new EightBallResponse() { Text = "Nope" },
|
||||||
|
new EightBallResponse() { Text = "No" },
|
||||||
|
new EightBallResponse() { Text = "My sources say no" },
|
||||||
|
new EightBallResponse() { Text = "Dont even think about it" },
|
||||||
|
new EightBallResponse() { Text = "Definitely no" },
|
||||||
|
new EightBallResponse() { Text = "NO - It may cause disease contraction" }
|
||||||
|
});
|
||||||
|
|
||||||
|
BotConfig.Add(bc);
|
||||||
|
|
||||||
|
this.SaveChanges();
|
||||||
|
}
|
||||||
|
if (!TypingArticles.Any())
|
||||||
|
{
|
||||||
|
//todo load default typing articles
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
@ -36,7 +120,7 @@ namespace NadekoBot.Services.Database
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Config
|
#region GuildConfig
|
||||||
|
|
||||||
var configEntity = modelBuilder.Entity<GuildConfig>();
|
var configEntity = modelBuilder.Entity<GuildConfig>();
|
||||||
configEntity
|
configEntity
|
||||||
@ -45,6 +129,15 @@ namespace NadekoBot.Services.Database
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region BotConfig
|
||||||
|
var botConfigEntity = modelBuilder.Entity<BotConfig>();
|
||||||
|
//botConfigEntity
|
||||||
|
// .HasMany(c => c.ModulePrefixes)
|
||||||
|
// .WithOne(mp => mp.BotConfig)
|
||||||
|
// .HasForeignKey(mp => mp.BotConfigId);
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region ClashOfClans
|
#region ClashOfClans
|
||||||
|
|
||||||
var callersEntity = modelBuilder.Entity<ClashCaller>();
|
var callersEntity = modelBuilder.Entity<ClashCaller>();
|
||||||
@ -63,6 +156,38 @@ namespace NadekoBot.Services.Database
|
|||||||
.IsUnique();
|
.IsUnique();
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Repeater
|
||||||
|
|
||||||
|
var repeaterEntity = modelBuilder.Entity<Repeater>();
|
||||||
|
|
||||||
|
repeaterEntity
|
||||||
|
.HasIndex(r => r.ChannelId)
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Currency
|
||||||
|
var currencyEntity = modelBuilder.Entity<Currency>();
|
||||||
|
|
||||||
|
currencyEntity
|
||||||
|
.HasIndex(c => c.UserId)
|
||||||
|
.IsUnique();
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region LogSettings
|
||||||
|
|
||||||
|
//var logSettingEntity = modelBuilder.Entity<LogSetting>();
|
||||||
|
|
||||||
|
//logSettingEntity
|
||||||
|
// .HasMany(ls => ls.IgnoredChannels)
|
||||||
|
// .WithOne(ls => ls.LogSetting)
|
||||||
|
// .HasPrincipalKey(ls => ls.id;
|
||||||
|
|
||||||
|
//logSettingEntity
|
||||||
|
// .HasMany(ls => ls.IgnoredVoicePresenceChannelIds)
|
||||||
|
// .WithOne(ls => ls.LogSetting);
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
protected abstract override void OnConfiguring(DbContextOptionsBuilder optionsBuilder);
|
protected abstract override void OnConfiguring(DbContextOptionsBuilder optionsBuilder);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,17 @@
|
|||||||
|
using NadekoBot.Services.Database.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NadekoBot.Services.Database.Repositories
|
||||||
|
{
|
||||||
|
public interface ICurrencyRepository : IRepository<Currency>
|
||||||
|
{
|
||||||
|
Currency GetOrCreate(ulong userId);
|
||||||
|
long GetUserCurrency(ulong userId);
|
||||||
|
bool TryUpdateState(ulong userId, long change);
|
||||||
|
IEnumerable<Currency> GetTopRichest(int count);
|
||||||
|
}
|
||||||
|
}
|
@ -11,5 +11,6 @@ namespace NadekoBot.Services.Database.Repositories
|
|||||||
public interface IGuildConfigRepository : IRepository<GuildConfig>
|
public interface IGuildConfigRepository : IRepository<GuildConfig>
|
||||||
{
|
{
|
||||||
GuildConfig For(ulong guildId);
|
GuildConfig For(ulong guildId);
|
||||||
|
IEnumerable<FollowedStream> GetAllFollowedStreams();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
using NadekoBot.Services.Database.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NadekoBot.Services.Database.Repositories
|
||||||
|
{
|
||||||
|
public interface IRepeaterRepository : IRepository<Repeater>
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
using NadekoBot.Services.Database.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NadekoBot.Services.Database.Repositories
|
||||||
|
{
|
||||||
|
public interface ITypingArticlesRepository : IRepository <TypingArticle>
|
||||||
|
{
|
||||||
|
TypingArticle GetRandom();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
using NadekoBot.Services.Database.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NadekoBot.Services.Database.Repositories
|
||||||
|
{
|
||||||
|
public interface IUnitConverterRepository : IRepository<ConvertUnit>
|
||||||
|
{
|
||||||
|
void AddOrUpdate(Func<ConvertUnit, bool> check, ConvertUnit toAdd, Func<ConvertUnit, ConvertUnit> toUpdate);
|
||||||
|
bool Empty();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
using NadekoBot.Services.Database.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace NadekoBot.Services.Database.Repositories.Impl
|
||||||
|
{
|
||||||
|
public class CurrencyRepository : Repository<Currency>, ICurrencyRepository
|
||||||
|
{
|
||||||
|
public CurrencyRepository(DbContext context) : base(context)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public Currency GetOrCreate(ulong userId)
|
||||||
|
{
|
||||||
|
var cur = _set.FirstOrDefault(c => c.UserId == userId);
|
||||||
|
|
||||||
|
if (cur == null)
|
||||||
|
{
|
||||||
|
_set.Add(cur = new Currency()
|
||||||
|
{
|
||||||
|
UserId = userId,
|
||||||
|
Amount = 0
|
||||||
|
});
|
||||||
|
_context.SaveChanges();
|
||||||
|
}
|
||||||
|
return cur;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<Currency> GetTopRichest(int count) =>
|
||||||
|
_set.OrderByDescending(c => c.Amount).Take(count).ToList();
|
||||||
|
|
||||||
|
public long GetUserCurrency(ulong userId) =>
|
||||||
|
GetOrCreate(userId).Amount;
|
||||||
|
|
||||||
|
public bool TryUpdateState(ulong userId, long change)
|
||||||
|
{
|
||||||
|
var cur = GetOrCreate(userId);
|
||||||
|
|
||||||
|
if (change == 0)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (change > 0)
|
||||||
|
{
|
||||||
|
cur.Amount += change;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//change is negative
|
||||||
|
if (cur.Amount + change >= 0)
|
||||||
|
{
|
||||||
|
cur.Amount += change;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -13,6 +13,14 @@ namespace NadekoBot.Services.Database.Repositories.Impl
|
|||||||
public GuildConfigRepository(DbContext context) : base(context)
|
public GuildConfigRepository(DbContext context) : base(context)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public new IEnumerable<GuildConfig> GetAll() =>
|
||||||
|
_set.Include(gc => gc.LogSetting)
|
||||||
|
.ThenInclude(ls => ls.IgnoredChannels)
|
||||||
|
.Include(gc => gc.LogSetting)
|
||||||
|
.ThenInclude(ls => ls.IgnoredVoicePresenceChannelIds)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets and creates if it doesn't exist a config for a guild.
|
/// Gets and creates if it doesn't exist a config for a guild.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -20,7 +28,10 @@ namespace NadekoBot.Services.Database.Repositories.Impl
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public GuildConfig For(ulong guildId)
|
public GuildConfig For(ulong guildId)
|
||||||
{
|
{
|
||||||
var config = _set.FirstOrDefault(c => c.GuildId == guildId);
|
var config = _set.Include(gc => gc.FollowedStreams)
|
||||||
|
.Include(gc => gc.LogSetting)
|
||||||
|
.ThenInclude(ls=>ls.IgnoredChannels)
|
||||||
|
.FirstOrDefault(c => c.GuildId == guildId);
|
||||||
|
|
||||||
if (config == null)
|
if (config == null)
|
||||||
{
|
{
|
||||||
@ -32,5 +43,10 @@ namespace NadekoBot.Services.Database.Repositories.Impl
|
|||||||
}
|
}
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IEnumerable<FollowedStream> GetAllFollowedStreams() =>
|
||||||
|
_set.Include(gc => gc.FollowedStreams)
|
||||||
|
.SelectMany(gc => gc.FollowedStreams)
|
||||||
|
.ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ namespace NadekoBot.Services.Database.Repositories.Impl
|
|||||||
|
|
||||||
public Task<Quote> GetRandomQuoteByKeywordAsync(ulong guildId, string keyword)
|
public Task<Quote> GetRandomQuoteByKeywordAsync(ulong guildId, string keyword)
|
||||||
{
|
{
|
||||||
var rng = new Random();
|
var rng = new NadekoRandom();
|
||||||
return _set.Where(q => q.Keyword == keyword).OrderBy(q => rng.Next()).FirstOrDefaultAsync();
|
return _set.Where(q => q.Keyword == keyword).OrderBy(q => rng.Next()).FirstOrDefaultAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,17 @@
|
|||||||
|
using NadekoBot.Services.Database.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace NadekoBot.Services.Database.Repositories.Impl
|
||||||
|
{
|
||||||
|
public class RepeaterRepository : Repository<Repeater>, IRepeaterRepository
|
||||||
|
{
|
||||||
|
public RepeaterRepository(DbContext context) : base(context)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
using NadekoBot.Services.Database.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace NadekoBot.Services.Database.Repositories.Impl
|
||||||
|
{
|
||||||
|
public class TypingArticlesRepository : Repository<TypingArticle>, ITypingArticlesRepository
|
||||||
|
{
|
||||||
|
private Random _rand = null;
|
||||||
|
private Random rand => _rand ?? (_rand = new NadekoRandom());
|
||||||
|
public TypingArticlesRepository(DbContext context) : base(context)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public TypingArticle GetRandom()
|
||||||
|
{
|
||||||
|
var skip = (int)(rand.NextDouble() * _set.Count());
|
||||||
|
return _set.Skip(skip).FirstOrDefault();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
using NadekoBot.Services.Database.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace NadekoBot.Services.Database.Repositories.Impl
|
||||||
|
{
|
||||||
|
public class UnitConverterRepository : Repository<ConvertUnit>, IUnitConverterRepository
|
||||||
|
{
|
||||||
|
public UnitConverterRepository(DbContext context) : base(context)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddOrUpdate(Func<ConvertUnit, bool> check, ConvertUnit toAdd, Func<ConvertUnit, ConvertUnit> toUpdate)
|
||||||
|
{
|
||||||
|
var existing = _set.FirstOrDefault(check);
|
||||||
|
if (existing != null)
|
||||||
|
{
|
||||||
|
existing = toUpdate.Invoke(existing);
|
||||||
|
}
|
||||||
|
else _set.Add(toAdd);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Empty() => !_set.Any();
|
||||||
|
}
|
||||||
|
}
|
@ -33,6 +33,17 @@ namespace NadekoBot.Services.Database
|
|||||||
private IBotConfigRepository _botConfig;
|
private IBotConfigRepository _botConfig;
|
||||||
public IBotConfigRepository BotConfig => _botConfig ?? (_botConfig = new BotConfigRepository(_context));
|
public IBotConfigRepository BotConfig => _botConfig ?? (_botConfig = new BotConfigRepository(_context));
|
||||||
|
|
||||||
|
private IRepeaterRepository _repeaters;
|
||||||
|
public IRepeaterRepository Repeaters => _repeaters ?? (_repeaters = new RepeaterRepository(_context));
|
||||||
|
|
||||||
|
private ICurrencyRepository _currency;
|
||||||
|
public ICurrencyRepository Currency => _currency ?? (_currency = new CurrencyRepository(_context));
|
||||||
|
private IUnitConverterRepository _conUnits;
|
||||||
|
public IUnitConverterRepository ConverterUnits => _conUnits ?? (_conUnits = new UnitConverterRepository(_context));
|
||||||
|
|
||||||
|
private ITypingArticlesRepository _typingArticles;
|
||||||
|
public ITypingArticlesRepository TypingArticles => _typingArticles ?? (_typingArticles = new TypingArticlesRepository(_context));
|
||||||
|
|
||||||
public UnitOfWork(NadekoContext context)
|
public UnitOfWork(NadekoContext context)
|
||||||
{
|
{
|
||||||
_context = context;
|
_context = context;
|
||||||
|
@ -15,28 +15,31 @@ namespace NadekoBot.Services.Impl
|
|||||||
private int messageCounter;
|
private int messageCounter;
|
||||||
private DiscordSocketClient client;
|
private DiscordSocketClient client;
|
||||||
private DateTime started;
|
private DateTime started;
|
||||||
|
private int commandsRan = 0;
|
||||||
|
|
||||||
public string BotVersion => "1.0-alpha";
|
public string BotVersion => "1.0-alpha";
|
||||||
|
|
||||||
public string Heap => Math.Round((double)GC.GetTotalMemory(false) / 1.MiB(), 2).ToString();
|
public string Heap => Math.Round((double)GC.GetTotalMemory(false) / 1.MiB(), 2).ToString();
|
||||||
|
|
||||||
|
|
||||||
public StatsService(DiscordSocketClient client)
|
public StatsService(DiscordSocketClient client, CommandHandler cmdHandler)
|
||||||
{
|
{
|
||||||
|
|
||||||
this.client = client;
|
this.client = client;
|
||||||
|
|
||||||
Reset();
|
Reset();
|
||||||
this.client.MessageReceived += _ => Task.FromResult(messageCounter++);
|
this.client.MessageReceived += _ => Task.FromResult(messageCounter++);
|
||||||
|
cmdHandler.CommandExecuted += (_, e) => commandsRan++;
|
||||||
|
|
||||||
this.client.Disconnected += _ => Reset();
|
this.client.Disconnected += _ => Reset();
|
||||||
}
|
}
|
||||||
public Task<string> Print() => Task.FromResult($@"`Author: Kwoth` `Library: Discord.Net`
|
public Task<string> Print() => Task.FromResult($@"`Author: Kwoth` `Library: Discord.Net`
|
||||||
`Bot Version: {BotVersion}`
|
`Bot Version: {BotVersion}`
|
||||||
`Bot id: {(client.GetCurrentUser()).Id}`
|
`Bot id: {(client.GetCurrentUser()).Id}`
|
||||||
`Owners' Ids:`
|
`Owners' Ids: {string.Join(", ", NadekoBot.Credentials.OwnerIds)}`
|
||||||
`Uptime: {GetUptimeString()}`
|
`Uptime: {GetUptimeString()}`
|
||||||
`Servers: {client.GetGuilds().Count} | TextChannels: {client.GetGuilds().SelectMany(g => g.GetChannels().Where(c => c is ITextChannel)).Count()} | VoiceChannels: {client.GetGuilds().SelectMany(g => g.GetChannels().Where(c => c is IVoiceChannel)).Count()}`
|
`Servers: {client.GetGuilds().Count} | TextChannels: {client.GetGuilds().SelectMany(g => g.GetChannels().Where(c => c is ITextChannel)).Count()} | VoiceChannels: {client.GetGuilds().SelectMany(g => g.GetChannels().Where(c => c is IVoiceChannel)).Count()}`
|
||||||
|
`Commands Ran this session: {commandsRan}`
|
||||||
`Messages: {messageCounter} ({messageCounter / (double)GetUptime().TotalSeconds:F2}/sec)` `Heap: {Heap} MB`");
|
`Messages: {messageCounter} ({messageCounter / (double)GetUptime().TotalSeconds:F2}/sec)` `Heap: {Heap} MB`");
|
||||||
|
|
||||||
public Task Reset()
|
public Task Reset()
|
||||||
|
72
src/NadekoBot/Services/NadekoRandom.cs
Normal file
72
src/NadekoBot/Services/NadekoRandom.cs
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NadekoBot.Services
|
||||||
|
{
|
||||||
|
public class NadekoRandom : Random
|
||||||
|
{
|
||||||
|
RandomNumberGenerator rng;
|
||||||
|
|
||||||
|
public NadekoRandom() : base()
|
||||||
|
{
|
||||||
|
rng = RandomNumberGenerator.Create();
|
||||||
|
}
|
||||||
|
|
||||||
|
private NadekoRandom(int Seed) : base(Seed)
|
||||||
|
{
|
||||||
|
rng = RandomNumberGenerator.Create();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int Next()
|
||||||
|
{
|
||||||
|
var bytes = new byte[sizeof(int)];
|
||||||
|
rng.GetBytes(bytes);
|
||||||
|
return Math.Abs(BitConverter.ToInt32(bytes, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int Next(int maxValue)
|
||||||
|
{
|
||||||
|
if (maxValue <= 0)
|
||||||
|
throw new ArgumentOutOfRangeException();
|
||||||
|
var bytes = new byte[sizeof(int)];
|
||||||
|
rng.GetBytes(bytes);
|
||||||
|
return Math.Abs(BitConverter.ToInt32(bytes, 0)) % maxValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int Next(int minValue, int maxValue)
|
||||||
|
{
|
||||||
|
if (minValue > maxValue)
|
||||||
|
throw new ArgumentOutOfRangeException();
|
||||||
|
if (minValue == maxValue)
|
||||||
|
return minValue;
|
||||||
|
var bytes = new byte[sizeof(int)];
|
||||||
|
rng.GetBytes(bytes);
|
||||||
|
var num = BitConverter.ToInt32(bytes, 0);
|
||||||
|
var sign = Math.Sign(BitConverter.ToInt32(bytes, 0));
|
||||||
|
return (sign * BitConverter.ToInt32(bytes, 0)) % (maxValue - minValue) + minValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void NextBytes(byte[] buffer)
|
||||||
|
{
|
||||||
|
rng.GetBytes(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override double Sample()
|
||||||
|
{
|
||||||
|
var bytes = new byte[sizeof(double)];
|
||||||
|
rng.GetBytes(bytes);
|
||||||
|
return Math.Abs(BitConverter.ToDouble(bytes, 0) / double.MaxValue + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override double NextDouble()
|
||||||
|
{
|
||||||
|
var bytes = new byte[sizeof(double)];
|
||||||
|
rng.GetBytes(bytes);
|
||||||
|
return BitConverter.ToDouble(bytes, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,204 +0,0 @@
|
|||||||
//--------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
||||||
//
|
|
||||||
// File: ObservableConcurrentDictionary.cs
|
|
||||||
//
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Collections.Specialized;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Threading;
|
|
||||||
|
|
||||||
namespace System.Collections.Concurrent
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Provides a thread-safe dictionary for use with data binding.
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="TKey">Specifies the type of the keys in this collection.</typeparam>
|
|
||||||
/// <typeparam name="TValue">Specifies the type of the values in this collection.</typeparam>
|
|
||||||
[DebuggerDisplay("Count={Count}")]
|
|
||||||
public class ObservableConcurrentDictionary<TKey, TValue> :
|
|
||||||
ICollection<KeyValuePair<TKey, TValue>>, IDictionary<TKey, TValue>,
|
|
||||||
INotifyCollectionChanged, INotifyPropertyChanged
|
|
||||||
{
|
|
||||||
private readonly SynchronizationContext _context;
|
|
||||||
private readonly ConcurrentDictionary<TKey, TValue> _dictionary;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes an instance of the ObservableConcurrentDictionary class.
|
|
||||||
/// </summary>
|
|
||||||
public ObservableConcurrentDictionary()
|
|
||||||
{
|
|
||||||
_context = AsyncOperationManager.SynchronizationContext;
|
|
||||||
_dictionary = new ConcurrentDictionary<TKey, TValue>();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Event raised when the collection changes.</summary>
|
|
||||||
public event NotifyCollectionChangedEventHandler CollectionChanged;
|
|
||||||
/// <summary>Event raised when a property on the collection changes.</summary>
|
|
||||||
public event PropertyChangedEventHandler PropertyChanged;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Notifies observers of CollectionChanged or PropertyChanged of an update to the dictionary.
|
|
||||||
/// </summary>
|
|
||||||
private void NotifyObserversOfChange()
|
|
||||||
{
|
|
||||||
var collectionHandler = CollectionChanged;
|
|
||||||
var propertyHandler = PropertyChanged;
|
|
||||||
if (collectionHandler != null || propertyHandler != null)
|
|
||||||
{
|
|
||||||
_context.Post(s =>
|
|
||||||
{
|
|
||||||
if (collectionHandler != null)
|
|
||||||
{
|
|
||||||
collectionHandler(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
|
|
||||||
}
|
|
||||||
if (propertyHandler != null)
|
|
||||||
{
|
|
||||||
propertyHandler(this, new PropertyChangedEventArgs("Count"));
|
|
||||||
propertyHandler(this, new PropertyChangedEventArgs("Keys"));
|
|
||||||
propertyHandler(this, new PropertyChangedEventArgs("Values"));
|
|
||||||
}
|
|
||||||
}, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Attempts to add an item to the dictionary, notifying observers of any changes.</summary>
|
|
||||||
/// <param name="item">The item to be added.</param>
|
|
||||||
/// <returns>Whether the add was successful.</returns>
|
|
||||||
private bool TryAddWithNotification(KeyValuePair<TKey, TValue> item)
|
|
||||||
{
|
|
||||||
return TryAddWithNotification(item.Key, item.Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Attempts to add an item to the dictionary, notifying observers of any changes.</summary>
|
|
||||||
/// <param name="key">The key of the item to be added.</param>
|
|
||||||
/// <param name="value">The value of the item to be added.</param>
|
|
||||||
/// <returns>Whether the add was successful.</returns>
|
|
||||||
private bool TryAddWithNotification(TKey key, TValue value)
|
|
||||||
{
|
|
||||||
bool result = _dictionary.TryAdd(key, value);
|
|
||||||
if (result) NotifyObserversOfChange();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Attempts to remove an item from the dictionary, notifying observers of any changes.</summary>
|
|
||||||
/// <param name="key">The key of the item to be removed.</param>
|
|
||||||
/// <param name="value">The value of the item removed.</param>
|
|
||||||
/// <returns>Whether the removal was successful.</returns>
|
|
||||||
private bool TryRemoveWithNotification(TKey key, out TValue value)
|
|
||||||
{
|
|
||||||
bool result = _dictionary.TryRemove(key, out value);
|
|
||||||
if (result) NotifyObserversOfChange();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Attempts to add or update an item in the dictionary, notifying observers of any changes.</summary>
|
|
||||||
/// <param name="key">The key of the item to be updated.</param>
|
|
||||||
/// <param name="value">The new value to set for the item.</param>
|
|
||||||
/// <returns>Whether the update was successful.</returns>
|
|
||||||
private void UpdateWithNotification(TKey key, TValue value)
|
|
||||||
{
|
|
||||||
_dictionary[key] = value;
|
|
||||||
NotifyObserversOfChange();
|
|
||||||
}
|
|
||||||
|
|
||||||
#region ICollection<KeyValuePair<TKey,TValue>> Members
|
|
||||||
void ICollection<KeyValuePair<TKey, TValue>>.Add(KeyValuePair<TKey, TValue> item)
|
|
||||||
{
|
|
||||||
TryAddWithNotification(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ICollection<KeyValuePair<TKey, TValue>>.Clear()
|
|
||||||
{
|
|
||||||
((ICollection<KeyValuePair<TKey, TValue>>)_dictionary).Clear();
|
|
||||||
NotifyObserversOfChange();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ICollection<KeyValuePair<TKey, TValue>>.Contains(KeyValuePair<TKey, TValue> item)
|
|
||||||
{
|
|
||||||
return ((ICollection<KeyValuePair<TKey, TValue>>)_dictionary).Contains(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ICollection<KeyValuePair<TKey, TValue>>.CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
|
|
||||||
{
|
|
||||||
((ICollection<KeyValuePair<TKey, TValue>>)_dictionary).CopyTo(array, arrayIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
int ICollection<KeyValuePair<TKey, TValue>>.Count {
|
|
||||||
get { return ((ICollection<KeyValuePair<TKey, TValue>>)_dictionary).Count; }
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ICollection<KeyValuePair<TKey, TValue>>.IsReadOnly {
|
|
||||||
get { return ((ICollection<KeyValuePair<TKey, TValue>>)_dictionary).IsReadOnly; }
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ICollection<KeyValuePair<TKey, TValue>>.Remove(KeyValuePair<TKey, TValue> item)
|
|
||||||
{
|
|
||||||
TValue temp;
|
|
||||||
return TryRemoveWithNotification(item.Key, out temp);
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IEnumerable<KeyValuePair<TKey,TValue>> Members
|
|
||||||
IEnumerator<KeyValuePair<TKey, TValue>> IEnumerable<KeyValuePair<TKey, TValue>>.GetEnumerator()
|
|
||||||
{
|
|
||||||
return ((ICollection<KeyValuePair<TKey, TValue>>)_dictionary).GetEnumerator();
|
|
||||||
}
|
|
||||||
|
|
||||||
IEnumerator IEnumerable.GetEnumerator()
|
|
||||||
{
|
|
||||||
return ((ICollection<KeyValuePair<TKey, TValue>>)_dictionary).GetEnumerator();
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IDictionary<TKey,TValue> Members
|
|
||||||
public void Add(TKey key, TValue value)
|
|
||||||
{
|
|
||||||
TryAddWithNotification(key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool ContainsKey(TKey key)
|
|
||||||
{
|
|
||||||
return _dictionary.ContainsKey(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ICollection<TKey> Keys {
|
|
||||||
get { return _dictionary.Keys; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool Remove(TKey key)
|
|
||||||
{
|
|
||||||
TValue temp;
|
|
||||||
return TryRemoveWithNotification(key, out temp);
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool TryGetValue(TKey key, out TValue value)
|
|
||||||
{
|
|
||||||
return _dictionary.TryGetValue(key, out value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool TryAdd(TKey key, TValue value)
|
|
||||||
{
|
|
||||||
return TryAddWithNotification(key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ICollection<TValue> Values {
|
|
||||||
get { return _dictionary.Values; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public TValue this[TKey key] {
|
|
||||||
get { return _dictionary[key]; }
|
|
||||||
set { UpdateWithNotification(key, value); }
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool TryRemove(TKey key, out TValue value)
|
|
||||||
{
|
|
||||||
return TryRemoveWithNotification(key, out value);
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user