Example #1
0
        public async Task CallTransactionMadeEventAsync(IDiscordMessageChannel m, User receiver, User giver, int amount)
        {
            try
            {
                TransactionPacket p = new TransactionPacket();
                p.discordChannel = m;
                p.discordUser    = new RuntimeUser(Bot.instance.Client.GetUser(receiver.Id.FromDbLong()));

                if (giver != null)
                {
                    p.giver = giver;
                }

                p.receiver = receiver;

                p.amount = amount;

                if (OnTransaction != null)
                {
                    await OnTransaction?.Invoke(p);
                }
            }
            catch (Exception e)
            {
                await MeruUtils.ReportErrorAsync(e);

                Log.WarningAt("achievement check failed", e.ToString());
            }
        }
Example #2
0
        /// <summary>
        /// Loads addons in ./modules folder
        /// </summary>
        public async Task Load(Bot bot)
        {
            if (!Directory.Exists(CurrentDirectory) || Directory.GetFiles(CurrentDirectory).Length == 0)
            {
                Log.Warning("No modules found, ignoring...");
                Directory.CreateDirectory(CurrentDirectory);
                return;
            }

            string[] allFiles = Directory.GetFiles(CurrentDirectory);

            foreach (string s in allFiles)
            {
                string newS = s.Split('/')[s.Split('/').Length - 1];
                newS = newS.Remove(newS.Length - 4);

                try
                {
                    if (!s.EndsWith(".dll"))
                    {
                        continue;
                    }

                    Assembly addon = Assembly.Load(File.ReadAllBytes(s));

                    if (addon.CreateInstance(newS + ".Addon") is IAddon currentAddon)
                    {
                        IAddonInstance aInstance = new RuntimeAddonInstance();
                        aInstance = await currentAddon.Create(aInstance);

                        foreach (IModule nm in aInstance.Modules)
                        {
                            IModule newModule = new RuntimeModule(nm);
                            await newModule.InstallAsync(bot);
                        }
                        Log.Done($"loaded Add-On {newS} successfully");
                    }
                }
                catch (Exception ex)
                {
                    await MeruUtils.ReportErrorAsync(ex);
                }
            }
        }