New lib, created some mock class for editing

The class would allow you to edit users LINQ-style , i just need to
convince voltana to make this happen
This commit is contained in:
Kwoth 2015-12-15 09:28:26 +01:00
parent 537595694a
commit fcb59b15ad
13 changed files with 123 additions and 40 deletions

View File

@ -13,10 +13,10 @@ namespace NadekoBot
{ {
public class Trivia : DiscordCommand public class Trivia : DiscordCommand
{ {
public static Dictionary<long, TriviaGame> runningTrivias; public static Dictionary<ulong, TriviaGame> runningTrivias;
public Trivia() : base() { public Trivia() : base() {
runningTrivias = new Dictionary<long, TriviaGame>(); runningTrivias = new Dictionary<ulong, TriviaGame>();
} }
public static TriviaGame StartNewGame(CommandEventArgs e) { public static TriviaGame StartNewGame(CommandEventArgs e) {
@ -29,7 +29,7 @@ namespace NadekoBot
return tg; return tg;
} }
public TriviaQuestion GetCurrentQuestion(long serverId) => runningTrivias[serverId].currentQuestion; public TriviaQuestion GetCurrentQuestion(ulong serverId) => runningTrivias[serverId].currentQuestion;
public override Func<CommandEventArgs, Task> DoFunc() => async e => public override Func<CommandEventArgs, Task> DoFunc() => async e =>
{ {
@ -103,12 +103,12 @@ namespace NadekoBot
public class TriviaGame { public class TriviaGame {
private DiscordClient client; private DiscordClient client;
private long _serverId; private ulong _serverId;
private long _channellId; private ulong _channellId;
public long ChannelId => _channellId; public ulong ChannelId => _channellId;
private Dictionary<long, int> users; private Dictionary<ulong, int> users;
public List<string> oldQuestions; public List<string> oldQuestions;
@ -121,7 +121,7 @@ namespace NadekoBot
private bool isQuit = false; private bool isQuit = false;
public TriviaGame(CommandEventArgs starter, DiscordClient client) { public TriviaGame(CommandEventArgs starter, DiscordClient client) {
this.users = new Dictionary<long, int>(); this.users = new Dictionary<ulong, int>();
this.client = client; this.client = client;
this._serverId = starter.Server.Id; this._serverId = starter.Server.Id;
this._channellId= starter.Channel.Id; this._channellId= starter.Channel.Id;
@ -196,7 +196,7 @@ namespace NadekoBot
if (currentQuestion == null || isQuit) if (currentQuestion == null || isQuit)
{ {
await ch.Send("Trivia bot stopping. :\\\n" + GetLeaderboard()); ch.Send("Trivia bot stopping. :\\\n" + GetLeaderboard());
FinishGame(); FinishGame();
return; return;
} }

View File

@ -6,13 +6,12 @@
public string Password; public string Password;
public string BotMention; public string BotMention;
public string GoogleAPIKey; public string GoogleAPIKey;
public long OwnerID; public ulong OwnerID;
public bool Crawl; public bool Crawl;
public string ParseID; public string ParseID;
public string ParseKey; public string ParseKey;
} }
public class AnimeResult
class AnimeResult
{ {
public int id; public int id;
public string airing_status; public string airing_status;
@ -28,8 +27,7 @@
"\n`Link:` http://anilist.co/anime/" + id + "\n`Link:` http://anilist.co/anime/" + id +
"\n`Synopsis:` " + description.Substring(0, description.Length > 500 ? 500 : description.Length) + "..." + "\n`Synopsis:` " + description.Substring(0, description.Length > 500 ? 500 : description.Length) + "..." +
"\n`img:` " + image_url_lge; "\n`img:` " + image_url_lge;
} }
class MangaResult class MangaResult
{ {
public int id; public int id;

View File

@ -7,11 +7,11 @@ namespace NadekoBot
{ {
class CopyCommand : DiscordCommand class CopyCommand : DiscordCommand
{ {
private List<long> CopiedUsers; private List<ulong> CopiedUsers;
public CopyCommand() : base() public CopyCommand() : base()
{ {
CopiedUsers = new List<long>(); CopiedUsers = new List<ulong>();
client.MessageReceived += Client_MessageReceived; client.MessageReceived += Client_MessageReceived;
} }

View File

@ -241,10 +241,14 @@ namespace NadekoBot.Modules
.Parameter("user",Discord.Commands.ParameterType.Required) .Parameter("user",Discord.Commands.ParameterType.Required)
.Do(async e => .Do(async e =>
{ {
if (e.Message.MentionedUsers.Any()) var usr = client.FindUsers(e.Channel, e.GetArg("user")).FirstOrDefault();
await e.Send( "Id of the user " + e.Message.MentionedUsers.First().Mention + " is " + e.Message.MentionedUsers.First().Id); if (usr == null)
else {
await e.Send( "You must mention a user."); await e.Send("You must mention a user.");
return;
}
await e.Send( "Id of the user " + usr.Name + " is " + usr.Id);
}); });
cgb.CreateCommand(".cid").Alias(".channelid") cgb.CreateCommand(".cid").Alias(".channelid")

View File

@ -94,7 +94,7 @@ namespace NadekoBot.Modules
} }
} }
private PokeType GetType(long id) { private PokeType GetType(ulong id) {
var remainder = id % 10; var remainder = id % 10;
if (remainder < 3) if (remainder < 3)
return PokeType.WATER; return PokeType.WATER;

View File

@ -22,6 +22,81 @@ namespace NadekoBot.Modules
} }
class EditUserBuilder {
public Discord.DiscordClient Client { get; set; }
public Discord.User User { get; set; }
private bool? ShouldMute { get; set; }
private bool? ShouldDeaf { get; set; }
private Discord.Channel TargetVoiceChannel { get; set; }
private Dictionary<Discord.EditMode, IEnumerable<Discord.Role>> TargetRoles { get; set; }
public EditUserBuilder(Discord.User user, Discord.DiscordClient client = null) {
this.User = user;
this.Client = client;
TargetRoles = new Dictionary<Discord.EditMode, IEnumerable<Discord.Role>>();
}
public EditUserBuilder Mute(bool mute = true) {
ShouldMute = mute;
return this;
}
public EditUserBuilder Deaf(bool mute = true)
{
ShouldDeaf = mute;
return this;
}
public EditUserBuilder VoiceChannel(Discord.Channel voiceChannel = null)
{
TargetVoiceChannel = voiceChannel;
return this;
}
public EditUserBuilder Roles(IEnumerable<Discord.Role> roles, Discord.EditMode mode)
{
if (TargetRoles.Keys.Contains(mode))
{
TargetRoles[mode] = TargetRoles[mode].Concat(roles);
}
else
{
TargetRoles[mode] = roles;
}
return this;
}
public async Task Apply() {
if (Client == null || User == null) return; //throw exception?
await Client.EditUser(User, ShouldMute, ShouldDeaf, TargetVoiceChannel);
foreach (var mode in TargetRoles.Keys) {
await Client.EditUser(User, null, null, null, TargetRoles[mode], mode);
}
return;
}
public EditUserBuilder SetUser(Discord.User user)
{
this.User = user;
return this;
}
public EditUserBuilder SetClient(Discord.DiscordClient client)
{
this.Client = client;
return this;
}
public EditUserBuilder DoWhen(Func<EditUserBuilder, EditUserBuilder> func, Func<bool> predicate) {
if (predicate())
return func(this);
return this;
}
}
public override void Install(ModuleManager manager) public override void Install(ModuleManager manager)
{ {
var client = NadekoBot.client; var client = NadekoBot.client;

View File

@ -15,7 +15,7 @@ namespace NadekoBot
// public static StatsCollector stats_collector; // public static StatsCollector stats_collector;
public static string botMention; public static string botMention;
public static string GoogleAPIKey; public static string GoogleAPIKey;
public static long OwnerID; public static ulong OwnerID;
static void Main() static void Main()
{ {

View File

@ -48,18 +48,6 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Discord.Net">
<HintPath>E:\Ostalo\Discord.Net\src\Discord.Net.Modules.Net45\bin\Debug\Discord.Net.dll</HintPath>
</Reference>
<Reference Include="Discord.Net.Audio">
<HintPath>E:\Ostalo\Discord.Net\src\Discord.Net.Audio.Net5\bin\Debug\Discord.Net.Audio.dll</HintPath>
</Reference>
<Reference Include="Discord.Net.Commands">
<HintPath>E:\Ostalo\Discord.Net\src\Discord.Net.Modules.Net45\bin\Debug\Discord.Net.Commands.dll</HintPath>
</Reference>
<Reference Include="Discord.Net.Modules">
<HintPath>E:\Ostalo\Discord.Net\src\Discord.Net.Modules.Net45\bin\Debug\Discord.Net.Modules.dll</HintPath>
</Reference>
<Reference Include="libvideo, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="libvideo, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\VideoLibrary.1.3.1\lib\portable-net45+win+wpa81+MonoAndroid10+xamarinios10+MonoTouch10\libvideo.dll</HintPath> <HintPath>..\packages\VideoLibrary.1.3.1\lib\portable-net45+win+wpa81+MonoAndroid10+xamarinios10+MonoTouch10\libvideo.dll</HintPath>
<Private>True</Private> <Private>True</Private>
@ -138,6 +126,24 @@
<Install>false</Install> <Install>false</Install>
</BootstrapperPackage> </BootstrapperPackage>
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="E:\Ostalo\Discord.Net\src\Discord.Net.Audio.Net5\Discord.Net.Audio.csproj">
<Project>{7bfef748-b934-4621-9b11-6302e3a9f6b3}</Project>
<Name>Discord.Net.Audio</Name>
</ProjectReference>
<ProjectReference Include="E:\Ostalo\Discord.Net\src\Discord.Net.Commands.Net45\Discord.Net.Commands.csproj">
<Project>{1b5603b4-6f8f-4289-b945-7baae523d740}</Project>
<Name>Discord.Net.Commands</Name>
</ProjectReference>
<ProjectReference Include="E:\Ostalo\Discord.Net\src\Discord.Net.Modules.Net45\Discord.Net.Modules.csproj">
<Project>{3091164f-66ae-4543-a63d-167c1116241d}</Project>
<Name>Discord.Net.Modules</Name>
</ProjectReference>
<ProjectReference Include="E:\Ostalo\Discord.Net\src\Discord.Net.Net45\Discord.Net.csproj">
<Project>{8d71a857-879a-4a10-859e-5ff824ed6688}</Project>
<Name>Discord.Net</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.

View File

@ -154,8 +154,8 @@ namespace NadekoBot
{ {
if (i == requestNumber) { if (i == requestNumber) {
var txt = reqObj.Get<string>("Request"); var txt = reqObj.Get<string>("Request");
var id = reqObj.Get<long>("UserId"); var id = reqObj.Get<ulong>("UserId");
var sid = reqObj.Get<long>("ServerId"); var sid = reqObj.Get<ulong>("ServerId");
reqObj.DeleteAsync(); reqObj.DeleteAsync();
return new ResolveRequestObject { Id = id, Text = txt, ServerId=sid }; return new ResolveRequestObject { Id = id, Text = txt, ServerId=sid };
} }
@ -165,8 +165,8 @@ namespace NadekoBot
} }
public class ResolveRequestObject { public class ResolveRequestObject {
public long Id; public ulong Id;
public long ServerId; public ulong ServerId;
public string Text; public string Text;
} }

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.