Commit 81cc9890 authored by Jeremy Pallats's avatar Jeremy Pallats 💬
Browse files

Add donation information mechanism.

- Text will be stored on server in text file.
- Add widgets for the two current options for donation.
parent 2b95b344
Loading
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -18,6 +18,13 @@ There is a [github repo] and a [gitlab repo]. While the project started on githu
will continue on gitlab at present and github will remain a mirror.
If people want to make forks and discuss issues that's fine but PRs are likely to be done on gitlab.

### Donate To Project

If you'd like to help cover server costs or buy me a coffe for development, see these buttons.

<a href="https://www.buymeacoffee.com/starcraftman" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-blue.png" width="11%" height="11%" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>
<noscript><a href="https://liberapay.com/starcraftman/donate"><img alt="Donate using Liberapay" src="https://liberapay.com/assets/widgets/donate.svg"></a></noscript>

### Install

This bot requires python >= 3.7. I suggest using pyenv to provide python and isolate from system.
+9 −0
Original line number Diff line number Diff line
@@ -754,6 +754,15 @@ class Dist(Action):
            await self.bot.send_message(self.msg.channel, msg)


class Donate(Action):
    """
    Information on how to donate. Command will not actually process anything here.
    """
    async def execute(self):
        with open(cog.util.CONF.paths.donate, 'r', encoding='utf-8') as fin:
            await self.bot.send_message(self.msg.channel, fin.read())


class Drop(Action):
    """
    Handle the logic of dropping a fort at a target.
+1 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ CONFIG_DEFAULTS = {
        '_hostile': "\U0001F534",
    },
    'paths': {
        'donate': 'data/donate.txt',
        'log_conf': 'data/log.yml',
        'service_json': 'data/service_sheets.json',
    },
+13 −0
Original line number Diff line number Diff line
@@ -214,6 +214,19 @@ def subs_dist(subs, prefix):
    sub.add_argument('system', nargs='+', help='The systems in question.')


@register_parser
def subs_donate(subs, prefix):
    """ Subcommand parsing for drop """
    desc = """Information on how to donate to the project.

**{prefix}donate**
        Information on how to donate funds to support development and server costs.
    """.format(prefix=prefix)
    sub = subs.add_parser(prefix + 'donate', description=desc, formatter_class=RawHelp)
    sub.set_defaults(cmd='Donate')
    CMD_MAP['Donate'] = 'donate'


@register_parser
def subs_drop(subs, prefix):
    """ Subcommand parsing for drop """
+23 −0
Original line number Diff line number Diff line
@@ -3,7 +3,9 @@ Tests against the cog.actions module.
These tests act as integration tests, checking almost the whole path.
Importantly, I have stubbed/mocked everything to do with discord.py and the gsheets calls.
"""
import os
import re
import shutil

import aiomock
import pytest
@@ -1612,6 +1614,27 @@ async def test_cmd_dist_invalid_args(f_bot):
        await action_map(msg, f_bot).execute()


@pytest.mark.asyncio
async def test_cmd_donate(f_bot):
    expected = "This is the donation message.\n"
    d_file = cog.util.CONF.paths.donate
    try:
        if os.path.exists(d_file):
            shutil.copyfile(d_file, d_file + '.bak')
        with open(d_file, 'w') as fout:
            fout.write(expected)

        msg = fake_msg_gears("!donate")
        await action_map(msg, f_bot).execute()

        f_bot.send_message.assert_called_with(msg.channel, expected)
    finally:
        try:
            os.rename(d_file + '.bak', d_file)
        except (OSError, FileNotFoundError):
            os.remove(d_file)


@pytest.mark.asyncio
async def test_cmd_kos_search(f_bot, f_kos):
    msg = fake_msg_gears("!kos search bad")