public async Task Kill() { // THe user to check for priviliges IGuildUser user = Context.User as IGuildUser; // If the user is an admin Log Sonnie off and kill the program if (user.IsAdmin()) { Debug.Log.Message("AdminCommands - Trying to log off"); // Get the application client DiscordSocketClient client = Context.Client as DiscordSocketClient; await Context.Channel.SendMessageAsync("Jamen vi ses så!"); // Save the list of users to the STB.UP file DataScanner <User> scanner = new DataScanner <User> (@"\Data\Users\STB.UP"); await scanner.WriteToFile(UserManager.GetUserList()); await client.LogoutAsync(); // Kill the program Environment.Exit(-1); } await Context.Channel.SendMessageAsync("Ups... Du er vidst ikke admin"); }
public async Task PlanEvent(string _name, string _timeSpan = null, string _description = null, string _otherInformation = null, string _prompt = null) { // Return a list with all currently stored events if (_name == "?") { if (EventManager.Events.Count != 0 && EventManager.Events != null) { string eventList = string.Empty; foreach (Event item in EventManager.Events) { eventList += item.Print(); } await Context.Message.Author.SendMessageAsync(eventList); return; } await Context.Channel.SendMessageAsync("Der er ingen events!"); return; } IGuildUser user = Context.User as IGuildUser; if (user.IsAdmin()) { // Cancel an event if (_name.ToLower() == "annuller") { string eventName = _timeSpan.ToLower(); EventManager.Events.Remove(EventManager.Events.Find(_event => _event.Name.ToLower() == eventName)); DataScanner <Event> scanner2 = new DataScanner <Event> (@"\Data\Events\STB.EP"); await scanner2.WriteToFile(EventManager.Events); await Context.Channel.SendMessageAsync("Oh... Det event er annulleret"); return; } // Extract the requered data from the passed string string [] rawDates = _timeSpan.Split('-'); DateTime startDate = new DateTime().Parse(rawDates [0]); DateTime endDate = new DateTime().Parse(rawDates [1]); DateTime prompt = new DateTime().Parse(_prompt); // Search for the auther of this event in the stored users and use his/her real name. If not found use the discord username instead string auther = (UserManager.SearchUserByID(Context.Message.Author.Id).Name ?? Context.Message.Author.Username); Event newEvent = new Event(_name, startDate, endDate, _description, _otherInformation, prompt, auther); EventManager.Events.Add(newEvent); // Save data to file DataScanner <Event> scanner = new DataScanner <Event> (@"\Data\Events\STB.EP"); await scanner.WriteToFile(EventManager.Events); await Context.Channel.SendMessageAsync($"Nyt event. Spændende!"); } }
public async Task VacationMode(string _value) { // The user to check for priviliges IGuildUser user = Context.User as IGuildUser; // Scanner for reading and writing from/to file DataScanner <Vacation> scanner = new DataScanner <Vacation> (@"\Data\Events\STB.VP"); // If the user is an admin set Sonnie in vacation mode if (user.IsAdmin()) { if (_value == "?") { string vacString = ((DiscordHandler.Instance.Vacation.ToString() == null) ? ("Jeg er ikke på ferie!") : ($"Jeg er på ferie fra: {DiscordHandler.Instance.Vacation.ToString ()}")); await Context.Channel.SendMessageAsync(vacString); return; } if (_value.ToLower() == "annuller") { await Context.Channel.SendMessageAsync("Ferien er annulleret"); DiscordHandler.Instance.Vacation = Vacation.SetInvalidVacation(); await scanner.WriteToFile(string.Empty); return; } DiscordHandler.Instance.Vacation = Vacation.Parse(_value); await Context.Channel.SendMessageAsync($"Jeg går på ferie fra: {DiscordHandler.Instance.Vacation.ToString ()}"); await scanner.WriteToFile(_value); return; } await Context.Channel.SendMessageAsync("Ups... Du er vidst ikke admin"); }
public async Task UserIs(string _ID, string _name) { // The user to chekc for priviliges IGuildUser user = Context.User as IGuildUser; if (user.IsAdmin()) { // Check if the user is already in the list User dataUser = UserManager.SearchUserByID(ulong.Parse(_ID)); // If the user is not in the list, create a new user object and add the user to the list if (dataUser == null) { // Get the server IGuild server = Context.Guild as IGuild; // Get the user based on the ID input IGuildUser entryUser = await server.GetUserAsync(ulong.Parse(_ID)) as IGuildUser; // Create the user object based on the input value User newEntry = new User(entryUser.Id, _name, entryUser.Mention, entryUser.Nickname, "false"); // Add the user to the list UserManager.AddUser(newEntry); // Save all users to the STB.UP file DataScanner <User> scanner = new DataScanner <User> (@"\Data\Users\STB.UP"); await scanner.WriteToFile(UserManager.GetUserList()); await Context.Channel.SendMessageAsync($"Jeg tilføjer {_name}, som {entryUser.Mention}."); return; } // If the user is in the list, just replace the name dataUser.SetName(_name); await Context.Channel.SendMessageAsync($"Jeg tilføjer {_name}, som {dataUser.Mention}."); return; } await Context.Channel.SendMessageAsync("Ups... Du er vidst ikke admin"); }
public async Task Save() { // THh user to chekc for priviliges IGuildUser user = Context.User as IGuildUser; //If the user is an admin save all usrs to the STB.UP file if (user.IsAdmin()) { Debug.Log.Message("AdminCommands - Force-Saving User and Event Profiles"); DataScanner <User> scanner = new DataScanner <User> (@"\Data\Users\STB.UP"); DataScanner <Event> eventScanner = new DataScanner <Event> (@"\Data\Events\STB.EP"); await scanner.WriteToFile(UserManager.GetUserList()); await eventScanner.WriteToFile(EventManager.Events); await Context.Channel.SendMessageAsync($"Jeg har skrevet alle navne og events ned, {Context.User.Mention}"); return; } await Context.Channel.SendMessageAsync("Ups... Du er vidst ikke admin"); }
public async Task AddMe([Summary("Your first name")] string _name) { // Search the list of users User user = UserManager.SearchUserByID(Context.Message.Author.Id); // If no user was found, create a new User object and add it to the list if (user == null) { user = new User(Context.User.Id, _name, Context.User.Mention); UserManager.AddUser(user); Debug.Log.Message($"ActiveCommands[Jeg er] - Added {user.ToString ()}"); } else // If a user was found just replace the name { user.SetName(_name); } // Save all users to file DataScanner <User> scanner = new DataScanner <User> (@"\Data\Users\STB.UP"); await scanner.WriteToFile(UserManager.GetUserList()); await ReplyAsync($"Jeg tilføjer {_name}, som dit navn."); }
public async Task MessageRecievedAsync(SocketMessage _rawMessage) { //Debug.Log.Message ( _rawMessage.ToString () ); // Make sure the message is of the right type and the message was from a user and not a bot if (!(_rawMessage is SocketUserMessage message) || message.Source != MessageSource.User) { return; } // The default Activity for the bot await this.client.SetGameAsync("Rumkyllinger I Rummet", "", ActivityType.Listening); // If the word network or netværk is in a message #region Network is for Losers check if (message.Content.ToLower().Contains("network") || message.Content.ToLower().Contains("netværk")) { await message.Channel.SendMessageAsync($"Netværk er for tabere, {message.Author.Mention}!"); // The server the bot is connected to var server = this.client.GetGuild(614042459957362698); Debug.Log.Message(server.Name.ToString()); #region If user is not in collection add the user var loser = server.GetUser(message.Author.Id); User rawUser = UserManager.SearchUserByID(loser.Id); if (rawUser == null) { User user = new User(loser.Id, "Ivan", loser.Mention, loser.Nickname); DataScanner <User> scanner = new DataScanner <User> (@"\Data\Users\STB.UP"); await scanner.WriteToFile(UserManager.GetUserList()); UserManager.AddUser(user); } else { rawUser.Nickname = loser.Nickname; } #endregion #region If user is not an admin chance nickname to "Taber" foreach (var role in loser.Roles) { if (role == server.GetRole(614097428756299784)) { return; } } await loser.ModifyAsync(user => user.Nickname = "Taber"); #endregion return; } #endregion #region Programming is the way forward check if (message.Content.ToLower().Contains("programmering") || message.Content.ToLower().Contains("code")) { await message.Channel.SendMessageAsync($"Programmering er vejen frem, {message.Author.Mention}!"); return; } #endregion #region Say Sorry to the Bot if (message.Content.ToLower().Contains(($"undskyld sonnie"))) { var server = this.client.GetGuild(614042459957362698); Debug.Log.Message(server.Name.ToString()); var loser = server.GetUser(message.Author.Id); User rawUser = UserManager.SearchUserByID(loser.Id); #region If the User is not an admin foreach (var role in loser.Roles) { if (role == server.GetRole(614097428756299784)) { await message.Channel.SendMessageAsync($"Du skal da ikke undskylde for noget, {message.Author.Mention}"); return; } } #endregion #region Give the user his Nickname back if (rawUser != null) { await loser.ModifyAsync(user => user.Nickname = rawUser.Nickname); await message.Channel.SendMessageAsync($"Det er så okay, {message.Author.Mention}!"); } #endregion } #endregion #region Citater #region Diktatur if (message.Content.ToLower() == "hvad er det her?") { await message.Channel.SendMessageAsync($"Det her er et diktatur, {message.Author.Mention}. Og diktatoren må skide i hjørnerne!"); } #endregion #region FuckDeAndreNiveau if (message.Content.ToLower() == "hvad arbejder vi ud fra?") { await message.Channel.SendMessageAsync($"Vi arbejder ud fra \"F**k De Andre Niveau\", {message.Author.Mention}! "); } #endregion #endregion var argPos = 0; char prefix = char.Parse(this.config ["Prefix"]); if (!(message.HasMentionPrefix(this.client.CurrentUser, ref argPos) || message.HasCharPrefix(prefix, ref argPos))) { return; } var context = new SocketCommandContext(this.client, message); await this.command.ExecuteAsync(context, argPos, this.services); }