Exemplo n.º 1
0
        public async Task CreateEventAsync([Remainder] string EventName)
        {//TODO: Add an Alias for additional commands, add this to HelpModule.
            // 1. Check to see if an event is already active.
            if (IsEventActive())
            {
                await ReplyAsync("", embed : EmbedTool.CommandError("An event is already active and a new one cannot be created."));
            }
            else
            {
                // 2. Check to see if the caller is an Event Organizer.
                var caller = Context.User as IGuildUser;
                if (IsEventOrganizer(caller, Context.Guild))
                {
                    // 3. Create the Event.
                    Event newEvent = new Event(Context.User.Id, EventName);
                    newEvent.Description      = "Not yet configured.";
                    newEvent.RulesURL         = "Not yet configured.";
                    newEvent.StartDate        = "Not yet configured.";
                    newEvent.RegistrationOpen = false;
                    newEvent.AcceptingSetups  = false;

                    // 4. Serialize the event into a JSON.
                    File.WriteAllText($"{Directory.GetCurrentDirectory()}{Path.DirectorySeparatorChar}Data{Path.DirectorySeparatorChar}Event.json", JsonConvert.SerializeObject(newEvent));
                    File.WriteAllText($"{Directory.GetCurrentDirectory()}{Path.DirectorySeparatorChar}Data{Path.DirectorySeparatorChar}Registration.json", JsonConvert.SerializeObject(ParticipantList));
                    Directory.CreateDirectory($"{Directory.GetCurrentDirectory()}{Path.DirectorySeparatorChar}Setups");
                    // 5. Confirm.
                    await ReplyAsync($"The event, {EventName}, has been created.");
                }
                else
                {
                    await ReplyAsync("You are not authorized to create events.");
                }
            }
        }
Exemplo n.º 2
0
        public async Task MessageReceivedAsync(SocketMessage rawMessage)
        {
            // Ignore system messages, or messages from other bots
            if (!(rawMessage is SocketUserMessage message))
            {
                return;
            }
            if (message.Source != MessageSource.User)
            {
                return;
            }
            var context = new SocketCommandContext(_discord, message);


            //Save Game Importing
            if (message.Attachments.Count == 1) //The message contains an attachment.
            {
                if (IsEventActive())
                {         //An event is active.
                    if (EventModule.IsParticipantRegistered(message.Author.Id))
                    {     //Check to see if the user is registered.
                        if (rawMessage.Attachments.FirstOrDefault <Attachment>().Filename.ToUpper().Contains("SA1"))
                        { //The message contains a save file. Download and process it.
                            string url            = rawMessage.Attachments.FirstOrDefault <Attachment>().Url;
                            string CacheDirectory = $"{Directory.GetCurrentDirectory()}{Path.DirectorySeparatorChar}Cache{Path.DirectorySeparatorChar}";
                            var    Client         = new WebClient();
                            Client.DownloadFile(new Uri(url), $"{CacheDirectory}{rawMessage.Author.Id}{rawMessage.Attachments.FirstOrDefault<Attachment>().Filename}");
                            Tools.BN6.SaveTool.ProcessSave($"{CacheDirectory}{rawMessage.Author.Id}{rawMessage.Attachments.FirstOrDefault<Attachment>().Filename}", rawMessage.Author.Id, EventModule.GetParticipant(rawMessage.Author).NetbattlerName);
                            EventModule.MarkAsSubmitted(rawMessage.Author);
                            await rawMessage.DeleteAsync();

                            await context.Channel.SendMessageAsync("Save file accepted.");
                        }
                        else if (rawMessage.Attachments.FirstOrDefault <Attachment>().Filename.ToUpper().Contains("SAV") || rawMessage.Attachments.FirstOrDefault <Attachment>().Filename.ToUpper().Contains(".SG"))
                        {
                            await rawMessage.DeleteAsync();

                            await context.Channel.SendMessageAsync("", false, EmbedTool.CommandError("I can only accept Save Files that are *.SA1 format. Please upload the correct save file."));
                        }
                    }
                }
            }


            // This value holds the offset where the prefix ends
            var argPos = 0;

            if (!(message.HasMentionPrefix(_discord.CurrentUser, ref argPos) || message.HasStringPrefix("!", ref argPos)))
            {
                return;
            }

            var result = await _commands.ExecuteAsync(context, argPos, _services);

            if (result.IsSuccess == false)
            {
                //The command failed?
            }
        }
Exemplo n.º 3
0
 public async Task UpdateEventDateAsync([Remainder] string Date)
 {
     if (IsEventActive() && IsEventOrganizer(Context.User as IGuildUser, Context.Guild))
     {
         UpdateEventData(EventFields.StartDate, Date);
         await ReplyAsync("The Event date has been upated.");
     }
     else
     {
         await ReplyAsync("", embed : EmbedTool.CommandError("There is not an active event or you are not authorized to make changes to the event."));
     }
 }
Exemplo n.º 4
0
 public async Task UpdateEventTitleAsync([Remainder] string EventTitle)
 {
     if (IsEventActive() && IsEventOrganizer(Context.User as IGuildUser, Context.Guild))
     {//The event is active and the caller is an authorized user.
         UpdateEventData(EventFields.Title, EventTitle);
         await ReplyAsync($"The event title has been updated to {EventTitle}.");
     }
     else
     {
         await ReplyAsync("", embed : EmbedTool.CommandError("There is not an active event or you are not authorized to make changes to the event."));
     }
 }
Exemplo n.º 5
0
        public async Task EventListAsync()
        {
            //Builds a list of participants to send to the organizer.
            if (IsEventOrganizer(Context.User as IGuildUser, Context.Guild))
            {
                SyncParticipantList(); //Ensure the List is up to date.
                string Result = $"**{GetActiveEvent().EventName} Participant List**\n\n";

                for (int i = 0; i < ParticipantList.Count; i++)
                {
                    Result += $"{ParticipantList[i].NetbattlerName} ({ParticipantList[i].UserID}) - Setup Submitted: {ParticipantList[i].SetupSubmitted.ToString()}\n";
                }
                await Context.User.SendMessageAsync(Result);
            }
            else
            {
                await ReplyAsync("", embed : EmbedTool.CommandError("You are not authorized to obtain the participant list."));
            }
        }
Exemplo n.º 6
0
 public async Task CloseRegistrationAsync()
 {
     if (IsEventActive() && IsEventOrganizer(Context.User as IGuildUser, Context.Guild))
     {//Is the event active?
         Event activeEvent = GetActiveEvent();
         if (activeEvent.RegistrationOpen == true)
         {//Is registration closed?
             UpdateEventData(EventFields.RegistrationOpen, "false");
             await ReplyAsync("Registration is now closed.");
         }
         else //No changes necessary.
         {
             await ReplyAsync("", embed : EmbedTool.CommandError("The event's registration is already closed."));
         }
     }
     else
     {
         await ReplyAsync("", embed : EmbedTool.CommandError("There is not an active event or you are not authorized to make changes to the event."));
     }
 }
Exemplo n.º 7
0
 public async Task JoinEventAsync([Remainder] string NetbattlerName)
 {
     SyncParticipantList();
     if (IsEventActive())
     {         //Is the event active?
         if (GetActiveEvent().RegistrationOpen == true)
         {     //Is registration open?
             if (IsParticipantRegistered(Context.User.Id) == true)
             { //The user is already registered.
                 await ReplyAsync("", embed : EmbedTool.CommandError($"You are already registered for the {GetActiveEvent().EventName} event."));
             }
             else
             {
                 if (VerifyNetbattlerName(NetbattlerName) == true)
                 { //Completing Task 56
                     //The Netbattler Name the user is attempting to use is already registered.
                     await ReplyAsync("The Netbattler Name you've selected is already in use. Please register with a different name.");
                 }
                 else
                 {  //The Netbattler Name is not registered.
                     EventParticipant newParticipant = new EventParticipant(NetbattlerName.Replace('@', ' '), Context.User.Id);
                     ParticipantList.Add(newParticipant);
                     WriteParticipantList();
                     await ToggleRole(Context.User as IGuildUser, RoleModule.GetRole("Official Netbattler", Context.Guild));//Add the Official Netbattler role to the user.
                     await ReplyAsync("", embed : EmbedTool.ChannelMessage($"You have registered for the event {GetActiveEvent().EventName} sucessfully!"));
                 }
             }
         }
         else //registration is closed.
         {
             await ReplyAsync("", embed : EmbedTool.CommandError($"{GetActiveEvent().EventName} is currently not accepting registrations."));
         }
     }
     else
     {
         await ReplyAsync("", embed : EmbedTool.CommandError("There currently isn't an active event."));
     }
 }
Exemplo n.º 8
0
        public async Task UpdateNetbattlerNameAsync([Remainder] string NewName)
        {
            SyncParticipantList();
            var caller = Context.User as IGuildUser;

            if (IsEventActive())
            {
                if (IsParticipantRegistered(caller.Id))
                {
                    GetParticipant(caller).NetbattlerName = NewName.Replace('@', ' ');
                    WriteParticipantList();
                    await ReplyAsync("Updated your Netbattler Name successfully.");
                }
                else
                {
                    await ReplyAsync("", embed : EmbedTool.CommandError($"You are not registered for {GetActiveEvent().EventName}."));
                }
            }
            else
            {
                await ReplyAsync("", embed : EmbedTool.CommandError("There currently isn't an active event."));
            }
        }
Exemplo n.º 9
0
 public async Task DropEventAsync()
 {
     SyncParticipantList();
     if (IsEventActive())
     {
         //We don't need to check for open registration to drop.
         var caller = Context.User as IGuildUser;
         if (IsParticipantRegistered(Context.User.Id) == true)
         {//The user is already registered.
             ParticipantList.Remove(GetParticipant(caller));
             WriteParticipantList();
             await ToggleRole(Context.User as IGuildUser, RoleModule.GetRole("Official Netbattler", Context.Guild)); //Remove the Official Netbattler role.
             await ReplyAsync("", embed : EmbedTool.ChannelMessage($"You have dropped from {GetActiveEvent().EventName}"));
         }
         else
         {
             await ReplyAsync("", embed : EmbedTool.CommandError($"You are not registered for the {GetActiveEvent().EventName} event."));
         }
     }
     else
     {
         await ReplyAsync("", embed : EmbedTool.CommandError("There currently isn't an active event."));
     }
 }