internal static Task Send(SocketMessage message) { if (!message.Author.IsBot) { if (message.Content.Contains(Program.commandChar)) { if (!UserTools.UserExists(message.Author.Id)) { Program.userList.Add(new User(message.Author.Id)); FileManipulation.LoadFile(message.Author.Id.ToString()); } try { string command = message.Content.Split(Program.commandChar)[0]; string rest = message.Content.Remove(0, command.Length + 1).Trim('|'); string[] content = rest.Split(Program.splitChar); CommandHandler.Send(message.Author.Id, command, content); } catch { message.Author.SendMessageAsync("Command is not correctly formatted, please try again or contact an administrator."); } } } return(Task.CompletedTask); }
public async Task BotInit() //starts the bot and initiates all handlers { _client = new DiscordSocketClient(new DiscordSocketConfig() { AlwaysDownloadUsers = true }); try { string token = FileManipulation.ReadFile("BotKey.txt");//Reads the token from file await _client.LoginAsync(TokenType.Bot, token); await _client.StartAsync(); await _client.SetStatusAsync(UserStatus.Online); _client.MessageReceived += MessageHandler.Send; while (true) { } } catch { System.Environment.Exit(5); } }
internal static void SaveAll() { foreach (var group in Program.groupList) { string output = "["; foreach (var info in group.Info) { output += "{"; foreach (var text in info.Content) { output += text; output += "|"; } output = output.Trim('|'); } FileManipulation.WriteFile(group.ID.ToString(), output); } }
public Group(params User[] users) { //sorts the users by their ID Users = users.OrderBy(u => u.ID).ToList(); ID = ""; Info = new List <Information>(); //Generates a group ID based on the user IDs, this will always be the same if it has the same users in a group List <string> ids = new List <string>(); foreach (var user in Users) { ids.Add(user.ID.ToString()); } foreach (var id in ids) { ID += id.Remove(18 / ids.Count); } FileManipulation.LoadFile(ID); foreach (var user in Users) { string output = "You have been added to a group with the members: "; foreach (var User in Users) { output += $"{Program._client.GetUser(User.ID).Username}, "; } output = output.Trim(' '); output = output.Trim(','); output += ".\n"; output += $"To access the group, use the ID: {ID} after the \"§\""; Program._client.GetUser(user.ID).SendMessageAsync(output); } }