refactor, new api

This commit is contained in:
Kwoth 2015-12-30 05:44:36 +01:00
parent 4c0f814f57
commit c443cb8268
19 changed files with 87 additions and 137 deletions

View File

@ -34,8 +34,8 @@ Global
{27A886F5-CDDA-4F4A-81EE-6DAFCCE9DE46}.Release|Any CPU.Build.0 = Release|Any CPU
{8D71A857-879A-4A10-859E-5FF824ED6688}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8D71A857-879A-4A10-859E-5FF824ED6688}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8D71A857-879A-4A10-859E-5FF824ED6688}.FullDebug|Any CPU.ActiveCfg = FullDebug|Any CPU
{8D71A857-879A-4A10-859E-5FF824ED6688}.FullDebug|Any CPU.Build.0 = FullDebug|Any CPU
{8D71A857-879A-4A10-859E-5FF824ED6688}.FullDebug|Any CPU.ActiveCfg = Debug|Any CPU
{8D71A857-879A-4A10-859E-5FF824ED6688}.FullDebug|Any CPU.Build.0 = Debug|Any CPU
{8D71A857-879A-4A10-859E-5FF824ED6688}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8D71A857-879A-4A10-859E-5FF824ED6688}.Release|Any CPU.Build.0 = Release|Any CPU
{3091164F-66AE-4543-A63D-167C1116241D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU

View File

@ -5,6 +5,7 @@ using System.Threading.Tasks;
using System.Security.Cryptography;
using Discord.Commands;
using Discord;
using Discord.Legacy;
namespace NadekoBot
{
@ -33,7 +34,7 @@ namespace NadekoBot
/// <param name="message">Message to be sent</param>
/// <returns></returns>
public static async Task<Message> Send(this CommandEventArgs e, string message)
=> await NadekoBot.client.SendMessage(e.Channel, message);
=> await e.Channel.SendMessage(message);
/// <summary>
/// Sends a message to the channel from which MessageEventArg came.
@ -43,7 +44,7 @@ namespace NadekoBot
/// <returns></returns>
public static async Task Send(this MessageEventArgs e, string message)
{
await NadekoBot.client.SendMessage(e.Channel, message);
await e.Channel.SendMessage(message);
}
/// <summary>
@ -54,7 +55,7 @@ namespace NadekoBot
/// <returns></returns>
public static async Task Send(this Channel c, string message)
{
await NadekoBot.client.SendMessage(c, message);
await c.SendMessage(message);
}
/// <summary>
@ -65,7 +66,7 @@ namespace NadekoBot
/// <returns></returns>
public static async Task Send(this User u, string message)
{
await NadekoBot.client.SendMessage(u, message);
await u.SendMessage(message);
}
/// <summary>
@ -111,5 +112,11 @@ namespace NadekoBot
list[n] = value;
}
}
public static void ForEach<T>(this IEnumerable<T> source, Action<T> action) {
foreach (T element in source) {
action(element);
}
}
}
}

View File

@ -8,6 +8,7 @@ using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Timers;
using Discord.Legacy;
namespace NadekoBot
{
@ -196,7 +197,9 @@ namespace NadekoBot
if (currentQuestion == null || isQuit)
{
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
ch.Send("Trivia bot stopping. :\\\n" + GetLeaderboard());
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
FinishGame();
return;
}
@ -242,7 +245,7 @@ namespace NadekoBot
foreach (var KeyValuePair in users)
{
str += "**" + client.GetUser(client.GetServer(_serverId), KeyValuePair.Key).Name + "** has " +KeyValuePair.Value + (KeyValuePair.Value == 1 ? "point." : "points.") + Environment.NewLine;
str += "**" + client.GetServer(_serverId).GetUser(KeyValuePair.Key).Name + "** has " +KeyValuePair.Value + (KeyValuePair.Value == 1 ? "point." : "points.") + Environment.NewLine;
}
return str;

View File

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Discord.Commands;
using Discord.Legacy;
namespace NadekoBot
{

View File

@ -5,6 +5,7 @@ using System.Threading.Tasks;
using Discord.Commands;
using System.Drawing;
using System.Drawing.Imaging;
using Discord.Legacy;
namespace NadekoBot
{
@ -35,7 +36,7 @@ namespace NadekoBot
}
Bitmap bitmap = ImageHandler.MergeImages(images);
await client.SendFile(e.Channel, "dice.png", ImageHandler.ImageToStream(bitmap, ImageFormat.Png));
await e.Channel.SendFile("dice.png", ImageHandler.ImageToStream(bitmap, ImageFormat.Png));
return;
}
else
@ -71,7 +72,7 @@ namespace NadekoBot
Bitmap bitmap = ImageHandler.MergeImages(dices.ToArray());
await e.Send( values.Count + " Dies rolled. Total: **"+values.Sum()+"** Average: **"+(values.Sum()/(1.0f*values.Count)).ToString("N2")+"**");
await client.SendFile(e.Channel, "dices.png", ImageHandler.ImageToStream(bitmap, ImageFormat.Png));
await e.Channel.SendFile("dices.png", ImageHandler.ImageToStream(bitmap, ImageFormat.Png));
}
catch (Exception)
{

View File

@ -4,6 +4,7 @@ using Discord.Commands;
using System.Drawing;
using System.Drawing.Imaging;
using System.Collections.Generic;
using Discord.Legacy;
namespace NadekoBot
{
@ -27,7 +28,7 @@ namespace NadekoBot
var isParsed = int.TryParse(e.GetArg("count"), out num);
if (!isParsed || num < 2)
{
await client.SendFile(e.Channel, cards.DrawACard().Path);
await e.Channel.SendFile(cards.DrawACard().Path);
return;
}
if (num > 5)
@ -47,7 +48,7 @@ namespace NadekoBot
images.Add(Image.FromFile(currentCard.Path));
}
Bitmap bitmap = ImageHandler.MergeImages(images);
await client.SendFile(e.Channel, images.Count + " cards.jpg", ImageHandler.ImageToStream(bitmap, ImageFormat.Jpeg));
await e.Channel.SendFile(images.Count + " cards.jpg", ImageHandler.ImageToStream(bitmap, ImageFormat.Jpeg));
if (cardObjects.Count == 5)
{
await e.Send(Cards.GetHandValue(cardObjects));

View File

@ -1,6 +1,7 @@
using System;
using System.Threading.Tasks;
using Discord.Commands;
using Discord.Legacy;
namespace NadekoBot
{
@ -18,11 +19,11 @@ namespace NadekoBot
int num = _r.Next(0, 2);
if (num == 1)
{
await client.SendFile(e.Channel, @"images/coins/heads.png");
await e.Channel.SendFile(@"images/coins/heads.png");
}
else
{
await client.SendFile(e.Channel, @"images/coins/tails.png");
await e.Channel.SendFile(@"images/coins/tails.png");
}
};

View File

@ -1,6 +1,7 @@
using System;
using System.Threading.Tasks;
using Discord.Commands;
using Discord.Legacy;
namespace NadekoBot
{

View File

@ -2,6 +2,7 @@
using System;
using System.Diagnostics;
using System.Linq;
using Discord.Legacy;
namespace NadekoBot.Modules
{
@ -26,13 +27,13 @@ namespace NadekoBot.Modules
.Do(async e =>
{
if (!e.User.ServerPermissions.ManageRoles) return;
var usr = client.FindUsers(e.Server, e.GetArg("user_name")).FirstOrDefault();
var usr = e.Server.FindUsers(e.GetArg("user_name")).FirstOrDefault();
if (usr == null) {
await e.Send( "You failed to supply a valid username");
return;
}
var role = client.FindRoles(e.Server, e.GetArg("role_name")).FirstOrDefault();
var role = e.Server.FindRoles(e.GetArg("role_name")).FirstOrDefault();
if (role == null) {
await e.Send( "You failed to supply a valid role");
return;
@ -40,11 +41,9 @@ namespace NadekoBot.Modules
try
{
await client.EditUser(usr, null, null,null, new Discord.Role[] { role }, Discord.EditMode.Add);
await usr.AddRoles(new Discord.Role[] { role });
await e.Send( $"Successfully added role **{role.Name}** to user **{usr.Mention}**");
}
catch (InvalidOperationException) { //fkin voltana and his shenanigans, fix role.Mention pl0x
}
catch (Exception ex)
{
await e.Send( "Failed to add roles. Most likely reason: Insufficient permissions.\n");
@ -59,14 +58,15 @@ namespace NadekoBot.Modules
.Do(async e =>
{
if (!e.User.ServerPermissions.ManageRoles) return;
var usr = client.FindUsers(e.Server, e.GetArg("user_name")).FirstOrDefault();
var usr = e.Server.FindUsers(e.GetArg("user_name")).FirstOrDefault();
if (usr == null)
{
await e.Send( "You failed to supply a valid username");
return;
}
var role = client.FindRoles(e.Server, e.GetArg("role_name")).FirstOrDefault();
var role = e.Server.FindRoles(e.GetArg("role_name")).FirstOrDefault();
if (role == null)
{
await e.Send( "You failed to supply a valid role");
@ -75,7 +75,7 @@ namespace NadekoBot.Modules
try
{
await client.EditUser(usr, null, null,null, new Discord.Role[]{ role }, Discord.EditMode.Remove);
await usr.RemoveRoles(new Discord.Role[] { role });
await e.Send( $"Successfully removed role **{role.Name}** from user **{usr.Mention}**");
}
catch (InvalidOperationException) {
@ -111,9 +111,9 @@ namespace NadekoBot.Modules
}
try
{
var r = await client.CreateRole(e.Server, e.GetArg("role_name"));
await client.EditRole(r, null,null, color);
await e.Send( $"Successfully created role **{r.Mention}**.");
var r = await e.Server.CreateRole(e.GetArg("role_name"));
await r.Edit(null,null, color);
await e.Send( $"Successfully created role **{r.ToString()}**.");
}
catch (Exception)
{
@ -131,7 +131,7 @@ namespace NadekoBot.Modules
if (e.User.ServerPermissions.BanMembers && e.Message.MentionedUsers.Any())
{
var usr = e.Message.MentionedUsers.First();
await client.BanUser(e.Message.MentionedUsers.First());
await usr.Server.Ban(usr);
await e.Send( "Banned user " + usr.Name + " Id: " + usr.Id);
}
}
@ -151,7 +151,7 @@ namespace NadekoBot.Modules
if (e.User.ServerPermissions.KickMembers && e.Message.MentionedUsers.Any())
{
var usr = e.Message.MentionedUsers.First();
await client.KickUser(e.Message.MentionedUsers.First());
await e.Message.MentionedUsers.First().Kick();
await e.Send("Kicked user " + usr.Name+" Id: "+usr.Id);
}
}
@ -170,7 +170,7 @@ namespace NadekoBot.Modules
{
if (e.User.ServerPermissions.ManageChannels)
{
await client.DeleteChannel(client.FindChannels(e.Server,e.GetArg("channel_name"),Discord.ChannelType.Voice).FirstOrDefault());
await e.Server.FindChannels(e.GetArg("channel_name"),Discord.ChannelType.Voice).FirstOrDefault()?.Delete();
await e.Send( $"Removed channel **{e.GetArg("channel_name")}**.");
}
}
@ -189,7 +189,7 @@ namespace NadekoBot.Modules
{
if (e.User.ServerPermissions.ManageChannels)
{
await client.CreateChannel(e.Server, e.GetArg("channel_name"), Discord.ChannelType.Voice);
await e.Server.CreateChannel(e.GetArg("channel_name"), Discord.ChannelType.Voice);
await e.Send( $"Created voice channel **{e.GetArg("channel_name")}**.");
}
}
@ -208,7 +208,7 @@ namespace NadekoBot.Modules
{
if (e.User.ServerPermissions.ManageChannels)
{
await client.DeleteChannel(client.FindChannels(e.Server, e.GetArg("channel_name"), Discord.ChannelType.Text).FirstOrDefault());
await e.Server.FindChannels(e.GetArg("channel_name"), Discord.ChannelType.Text).FirstOrDefault()?.Delete();
await e.Send( $"Removed text channel **{e.GetArg("channel_name")}**.");
}
}
@ -227,7 +227,7 @@ namespace NadekoBot.Modules
{
if (e.User.ServerPermissions.ManageChannels)
{
await client.CreateChannel(e.Server, e.GetArg("channel_name"), Discord.ChannelType.Text);
await e.Server.CreateChannel(e.GetArg("channel_name"), Discord.ChannelType.Text);
await e.Send( $"Added text channel **{e.GetArg("channel_name")}**.");
}
}
@ -241,7 +241,7 @@ namespace NadekoBot.Modules
.Parameter("user",Discord.Commands.ParameterType.Required)
.Do(async e =>
{
var usr = client.FindUsers(e.Channel, e.GetArg("user")).FirstOrDefault();
var usr = e.Channel.FindUsers(e.GetArg("user")).FirstOrDefault();
if (usr == null)
{
await e.Send("You must mention a user.");
@ -269,8 +269,8 @@ namespace NadekoBot.Modules
.Description("Shows some basic stats for nadeko")
.Do(async e =>
{
int serverCount = client.AllServers.Count();
int uniqueUserCount = client.AllUsers.Count();
int serverCount = client.Servers.Count();
int uniqueUserCount = client.Servers.Sum(s=>s.Users.Count());
var time = (DateTime.Now - Process.GetCurrentProcess().StartTime);
string uptime = " " + time.Days + " days, " + time.Hours + " hours, and " + time.Minutes + " minutes.";

View File

@ -11,6 +11,7 @@ using System.Drawing;
using System.IO;
using System.Text;
using System.Drawing.Imaging;
using Discord.Legacy;
namespace NadekoBot.Modules
{
@ -95,7 +96,7 @@ namespace NadekoBot.Modules
}
else
{
var kw = client.GetUser(e.Server, NadekoBot.OwnerID);
var kw = e.Server.GetUser(NadekoBot.OwnerID);
if (kw != null && kw.Status == UserStatus.Online)
{
await e.Send(e.User.Mention + " I am great as long as " + kw.Mention + " is with me.");
@ -114,7 +115,7 @@ namespace NadekoBot.Modules
{
List<string> insults = new List<string> { " you are a poop.", " you jerk.", " i will eat you when i get my powers back." };
Random r = new Random();
var u = client.FindUsers(e.Channel, e.GetArg("mention")).FirstOrDefault();
var u = e.Channel.FindUsers(e.GetArg("mention")).FirstOrDefault();
if (u == null) {
await e.Send("Invalid user specified.");
@ -142,7 +143,7 @@ namespace NadekoBot.Modules
{
List<string> praises = new List<string> { " You are cool.", " You are nice... But don't get any wrong ideas.", " You did a good job." };
Random r = new Random();
var u = client.FindUsers(e.Channel, e.GetArg("mention")).FirstOrDefault();
var u = e.Channel.FindUsers(e.GetArg("mention")).FirstOrDefault();
if (u == null)
{
@ -225,7 +226,7 @@ namespace NadekoBot.Modules
.Parameter("user", ParameterType.Unparsed)
.Do(async e =>
{
var usr = client.FindUsers(e.Channel, e.GetArg("user")).FirstOrDefault();
var usr = e.Channel.FindUsers(e.GetArg("user")).FirstOrDefault();
string text = "";
if (usr == null)
{
@ -234,7 +235,7 @@ namespace NadekoBot.Modules
else {
text = usr.Name;
}
await client.SendFile(e.Channel, "ripzor_m8.png", RipName(text));
await e.Channel.SendFile("ripzor_m8.png", RipName(text));
});
cgb.CreateCommand("j")
@ -244,7 +245,7 @@ namespace NadekoBot.Modules
{
try
{
await client.AcceptInvite(client.GetInvite(e.Args[0]).Result);
await (await client.GetInvite(e.Args[0])).Accept();
await e.Send("I got in!");
}
catch (Exception)
@ -363,7 +364,7 @@ namespace NadekoBot.Modules
if (msgs.Count() > 0)
msg = msgs.FirstOrDefault();
else {
var msgsarr = await client.DownloadMessages(e.Channel, 10000);
var msgsarr = await e.Channel.DownloadMessages(10000);
msg = msgsarr
.Where(m => m.MentionedUsers.Contains(e.User))
.OrderBy(m => m.Timestamp)
@ -464,7 +465,7 @@ namespace NadekoBot.Modules
if (sc != null)
{
await e.Send(e.User.Mention + " Request resolved, notice sent.");
await client.GetUser(client.GetServer(sc.ServerId), sc.Id).Send("**This request of yours has been resolved:**\n" + sc.Text);
await client.GetServer(sc.ServerId).GetUser(sc.Id).Send("**This request of yours has been resolved:**\n" + sc.Text);
}
else
{
@ -487,10 +488,10 @@ namespace NadekoBot.Modules
{
if (e.Channel.Messages.Count() < 50)
{
await client.DownloadMessages(e.Channel, 100);
await e.Channel.DownloadMessages(100);
}
await client.DeleteMessages(e.Channel.Messages.Where(msg => msg.User.Id == client.CurrentUser.Id));
e.Channel.Messages.Where(msg => msg.User.Id == client.CurrentUser.Id).ForEach(async m => await m.Delete());
}
catch (Exception)
@ -515,9 +516,9 @@ namespace NadekoBot.Modules
using (MemoryStream ms = new MemoryStream())
using (Image img = Image.FromFile("images/hidden.png"))
{
img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
img.Save(ms, ImageFormat.Png);
await client.EditProfile("", null, null, null, ms, ImageType.Png);
await client.CurrentUser.Edit(NadekoBot.password, null, null, null, ms, ImageType.Png);
}
await e.Send("*hides*");
}
@ -538,7 +539,7 @@ namespace NadekoBot.Modules
{
img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
await client.EditProfile("", null, null, null, ms, ImageType.Jpeg);
await client.CurrentUser.Edit(NadekoBot.password, null, null, null, ms, ImageType.Jpeg);
}
await e.Send("*unhides*");
}
@ -555,10 +556,10 @@ namespace NadekoBot.Modules
int i = 0;
int j = 0;
string invites = "";
foreach (var s in client.AllServers) {
foreach (var s in client.Servers) {
try
{
var invite = await client.CreateInvite(s, 0, 0);
var invite = await s.CreateInvite(0);
invites+=invite.Url+"\n";
i++;
}
@ -585,17 +586,17 @@ namespace NadekoBot.Modules
}
randServerSW.Reset();
while (true) {
var server = client.AllServers.OrderBy(x => rng.Next()).FirstOrDefault();
var server = client.Servers.OrderBy(x => rng.Next()).FirstOrDefault();
if (server == null)
continue;
try
{
var inv = await client.CreateInvite(server, 100, 5);
var inv = await server.CreateInvite(100, 5);
await e.Send("**Server:** " + server.Name +
"\n**Owner:** " + server.Owner.Name +
"\n**Channels:** " + server.Channels.Count() +
"\n**Total Members:** " + server.Members.Count() +
"\n**Online Members:** " + server.Members.Where(u => u.Status == UserStatus.Online).Count() +
"\n**Channels:** " + server.AllChannels.Count() +
"\n**Total Members:** " + server.Users.Count() +
"\n**Online Members:** " + server.Users.Where(u => u.Status == UserStatus.Online).Count() +
"\n**Invite:** " + inv.Url);
break;
}
@ -608,7 +609,7 @@ namespace NadekoBot.Modules
.Description("Shows a mentioned person's avatar. **Usage**: ~av @X")
.Do(async e =>
{
var usr = client.FindUsers(e.Channel, e.GetArg("mention")).FirstOrDefault();
var usr = e.Channel.FindUsers(e.GetArg("mention")).FirstOrDefault();
if (usr == null) {
await e.Send("Invalid user specified.");
return;

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Discord.Modules;
using Discord.Legacy;
namespace NadekoBot.Modules
{
@ -25,7 +26,7 @@ namespace NadekoBot.Modules
.Do(async e =>
{
var usr = NadekoBot.client.FindUsers(e.Server,e.GetArg("target")).FirstOrDefault();
var usr = e.Server.FindUsers(e.GetArg("target")).FirstOrDefault();
var usrType = GetType(usr.Id);
string response = "";
int dmg = GetDamage(usrType, e.GetArg("attack_type").ToLowerInvariant());
@ -44,7 +45,7 @@ namespace NadekoBot.Modules
.Parameter("target", Discord.Commands.ParameterType.Required)
.Do(async e =>
{
var usr = NadekoBot.client.FindUsers(e.Server, e.GetArg("target")).FirstOrDefault();
var usr = e.Server.FindUsers(e.GetArg("target")).FirstOrDefault();
if (usr == null) {
await e.Send("No such person.");
}

View File

@ -12,6 +12,7 @@ using System.Collections.Concurrent;
using VideoLibrary;
using System.Threading;
using System.Diagnostics;
using Discord.Legacy;
namespace NadekoBot.Modules
{
@ -143,7 +144,7 @@ namespace NadekoBot.Modules
.Do(async e =>
{
if (Voice != null) return;
VoiceChannel = client.FindChannels(e.Server, e.GetArg("ChannelName").Trim(), ChannelType.Voice).FirstOrDefault();
VoiceChannel = e.Server.FindChannels(e.GetArg("ChannelName").Trim(), ChannelType.Voice).FirstOrDefault();
//Voice = await client.JoinVoiceServer(VoiceChannel);
Exit = false;
NextSong = false;

View File

@ -12,6 +12,7 @@ using System.Reflection;
using System.Xml;
using Newtonsoft.Json;
using System.Net.Http;
using Discord.Legacy;
namespace NadekoBot.Modules
{
@ -22,81 +23,6 @@ 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)
{
var client = NadekoBot.client;

View File

@ -6,6 +6,7 @@ using Parse;
using Discord.Commands;
using NadekoBot.Modules;
using Discord.Modules;
using Discord.Legacy;
namespace NadekoBot
{
@ -16,6 +17,7 @@ namespace NadekoBot
public static string botMention;
public static string GoogleAPIKey;
public static ulong OwnerID;
public static string password;
static void Main()
{
@ -27,6 +29,7 @@ namespace NadekoBot
botMention = c.BotMention;
GoogleAPIKey = c.GoogleAPIKey;
OwnerID = c.OwnerID;
password = c.Password;
}
catch (Exception)
{
@ -55,10 +58,10 @@ namespace NadekoBot
//stats_collector = new StatsCollector(commandService);
//add command service
var commands = client.AddService(commandService);
var commands = client.Services.Add<CommandService>(commandService);
//create module service
var modules = client.AddService(new ModuleService());
var modules = client.Services.Add<ModuleService>(new ModuleService());
//install modules
modules.Install(new Administration(), "Administration", FilterType.Unrestricted);

View File

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Timers;
using Discord.Legacy;
namespace NadekoBot
{
@ -68,7 +69,7 @@ namespace NadekoBot
private async void TryJoin(MessageEventArgs e, string code) {
try
{
await NadekoBot.client.AcceptInvite(await NadekoBot.client.GetInvite(code));
await (await NadekoBot.client.GetInvite(code)).Accept();
await e.Send(e.User.Mention + " I joined it, thanks :)");
DEBUG_LOG("Sucessfuly joined server with code " + code);
DEBUG_LOG("Here is a link for you: discord.gg/" + code);
@ -80,7 +81,9 @@ namespace NadekoBot
}
public static void DEBUG_LOG(string text) {
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
NadekoBot.client.GetChannel(119365591852122112).Send(text);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
}
private void StartCollecting() {
@ -91,8 +94,8 @@ namespace NadekoBot
{
var obj = new ParseObject("Stats");
dataLastSent = "Data last sent at: "+DateTime.Now.Hour+":"+DateTime.Now.Minute;
obj["OnlineUsers"] = NadekoBot.client.AllUsers.Count();
obj["ConnectedServers"] = NadekoBot.client.AllServers.Count();
obj["OnlineUsers"] = NadekoBot.client.Servers.Sum(x=>x.Users.Count());
obj["ConnectedServers"] = NadekoBot.client.Servers.Count();
obj.SaveAsync();
};

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.