Exemple #1
0
        public async Task Collect(Player player, Discord.WebSocket.ISocketMessageChannel channel)
        {
            if (player != null)
            {
                player.KCoins += kuts;
                if (content != null && content.Count > 0 && !player.inventory.Add(content, -1))
                {
                    await channel.SendMessageAsync("Inventory may not contain all rewards");

                    return;
                }

                player.SaveFileMongo();
                await channel.SendMessageAsync("Mail collected and deleted successfully.");
            }

            await Database.DeleteRecord <Mail, Guid>(null, _id);
        }
Exemple #2
0
        /**
         * Basically, this calls an asynchronous main loop.
         * Because we assume the program run so fast that it runs asynchronously, there's nothing wrong with this.
         */
        /**
         * From here, I'll try to make the code looks neat and explanatory :)
         * */
        public async Task MainAsync(string[] args)
        {
#if BUILD
            SerializableUpdateInfo build_info = new SerializableUpdateInfo();
            build_info.Serialize(constants.path_here);
#else
            Updater.Program.start(args);
#endif
            //Initialize elements
            client = new Discord.WebSocket.
                     DiscordSocketClient(bot_conf.socket_config);
            command_serv = new Discord.Commands.CommandService();
            service      = new ServiceCollection().BuildServiceProvider();

            //Delegates
            client.Log             += on_client_log;
            client.MessageReceived += on_message_received;
            client.Ready           += start;
#if TRACE
            Console.WriteLine("Path.Location = " + program_const.execution_path[0] + "\n" + "Path.CodeBase = " + program_const.execution_path[1] + "");
            //Console.WriteLine("main_dev_channel = " + main_dev_channel.Name);
#endif
            await load_commands();

            Amonikano.Library.AmonikanoCommands.CoreModule.InitializeHelpNoReply();
            await client.LoginAsync(TokenType.Bot, bot_const.token);

            Console.WriteLine("client.LoginAsync() called, awaiting client.StartAsync()");
            await client.StartAsync();

            Console.WriteLine("client.StartAsync() finished, awaiting Task.Delay(-1)");
            //AssignMainDevChannel();

            while (true)
            {
                string input;
                input = Console.ReadLine();
#if TRACE
                Console.WriteLine("Input was: " + input);
#endif
                //Command
                //Amonikano.Library.ConsoleCommands.GeneralExecution.ExecuteCommand(input.Split(' '));
                switch (input)
                {
                case "inv_web":
                    Console.WriteLine(inv_webpage);
                    break;

                case "force_shutdown":
                    goto shutdown;
                }
            }
shutdown:
            Console.WriteLine("main() ended");
            await main_dev_channel.SendMessageAsync(bot_conf.shutdown_message);
        }
Exemple #3
0
        public static async Task SendCardAndReactions(List <Discord.Emoji> reactions, Discord.Embed embed, Discord.WebSocket.ISocketMessageChannel channel)
        {
            var message = await channel.SendMessageAsync("", embed : embed);

            // loop itself is async so we get them in the right order
            var reacionResults = reactions.Select(async x =>
                                                  await message.AddReactionAsync(x)
                                                  );
            await Task.WhenAll(reacionResults);

            return;
        }
        private async Task GuildHandler_ReactionAdded(Cacheable <IUserMessage, ulong> arg1, Discord.WebSocket.ISocketMessageChannel arg2, Discord.WebSocket.SocketReaction arg3)
        {
            if (EnableHyperlinkReactions)
            {
                NestedDefinitionButton button = _nestedButtons.FirstOrDefault(x => x.MessageId == arg1.Id);
                if (button != null && !arg3.User.GetValueOrDefault().IsBot)
                {
                    int emoji = ReactionEmojis.ToList().IndexOf(arg3.Emote.Name);
                    if (button.Contains(emoji))
                    {
                        string word = button.Consume(emoji);
                        var    def  = await UrbanDefinition.Get(word, EnableHyperlinkReactions);

                        var msg = await arg2.SendMessageAsync(null, false, def.ToEmbed());
                        await AddNestedDefReactions(def, msg);
                    }
                }
            }
        }