Skip to content

Commit

Permalink
Update branch.repo refewrences (#284)
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxdaemon authored Jan 19, 2021
1 parent c13552f commit a4a71b6
Show file tree
Hide file tree
Showing 14 changed files with 364 additions and 262 deletions.
17 changes: 0 additions & 17 deletions .github/workflows/mirror.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/pythonapp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ name: Python application
on:
push:
branches:
- master
- main
pull_request:
branches:
- master
- main
jobs:
build:
strategy:
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ This project uses [pre-commit]

## Submit Changes
1. Push your changes to a topic branch in your fork of the repository.
2. Open a pull request to the original repository and choose the `master` branch.
2. Open a pull request to the original repository and choose the `main` branch.
3. Correct any issues shown by the automated checks
4. Join the [IRC channel] if you have any questions or concerns, or if you just want to talk with other devs

Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# CloudBot
![Python application](https://github.com/TotallyNotRobots/CloudBot/workflows/Python%20application/badge.svg)
[![CodeFactor](https://www.codefactor.io/repository/github/totallynotrobots/cloudbot/badge/master)](https://www.codefactor.io/repository/github/totallynotrobots/cloudbot/overview/master)
[![codebeat badge](https://codebeat.co/badges/80316f30-26c0-44ec-b228-9158815d1995)](https://codebeat.co/projects/github-com-totallynotrobots-cloudbot-master)
[![codecov](https://codecov.io/gh/TotallyNotRobots/CloudBot/branch/master/graph/badge.svg)](https://codecov.io/gh/TotallyNotRobots/CloudBot)
[![CodeFactor](https://www.codefactor.io/repository/github/totallynotrobots/cloudbot/badge/main)](https://www.codefactor.io/repository/github/totallynotrobots/cloudbot/overview/main)
[![codebeat badge](https://codebeat.co/badges/80316f30-26c0-44ec-b228-9158815d1995)](https://codebeat.co/projects/github-com-totallynotrobots-cloudbot-main)
[![codecov](https://codecov.io/gh/TotallyNotRobots/CloudBot/branch/main/graph/badge.svg)](https://codecov.io/gh/TotallyNotRobots/CloudBot)

CloudBot is a simple, fast, expandable open-source Python IRC Bot!

## Getting CloudBot

You have a few options for getting the bot, you can:
* Clone the `master` branch of this repository, using `git pull` to update
* Clone the `main` branch of this repository, using `git pull` to update
* Download the [latest source]
* Download the [latest release]

Expand Down Expand Up @@ -90,6 +90,6 @@ Translations are Powered by [Yandex.Translate](https://translate.yandex.com)

This product uses data from <a href="http://wordnik.com">http://wordnik.com</a> in accordance with the wordnik.com API <a href="http://developer.wordnik.com/#!/terms">terms of service</a>.

[latest source]: https://github.com/TotallyNotRobots/CloudBot/archive/master.zip
[latest source]: https://github.com/TotallyNotRobots/CloudBot/archive/main.zip
[latest release]: https://github.com/TotallyNotRobots/CloudBot/releases/latest
[TheTVDB.com]: https://thetvdb.com/
5 changes: 3 additions & 2 deletions cloudbot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def exit_gracefully(signum, frame):
stopped_while_restarting = True
else:
async_util.run_coroutine_threadsafe(
_bot.stop("Killed (Received SIGINT {})".format(signum)), _bot.loop
_bot.stop("Killed (Received SIGINT {})".format(signum)),
_bot.loop,
)

logger.warning("Bot received Signal Interrupt (%s)", signum)
Expand All @@ -51,7 +52,7 @@ def exit_gracefully(signum, frame):

signal.signal(signal.SIGINT, exit_gracefully)

# start the bot master
# start the bot

# CloudBot.run() will return True if it should restart, False otherwise
restart = _bot.run()
Expand Down
28 changes: 15 additions & 13 deletions cloudbot/config.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
import json
import logging
import os
import sys
import time
from collections import OrderedDict
from pathlib import Path

logger = logging.getLogger("cloudbot")


class Config(OrderedDict):
"""
:type filename: str
:type path: str
:type bot: cloudbot.bot.CloudBot
"""

def __init__(self, bot, *args, **kwargs):
def __init__(self, bot, *, filename="config.json"):
"""
:type bot: cloudbot.bot.CloudBot
:type args: list
:type kwargs: dict
"""
super().__init__(*args, **kwargs)
self.filename = "config.json"
self.path = os.path.abspath(self.filename)
super().__init__()
self.filename = filename
self.path = Path(self.filename).resolve()
self.bot = bot
self.update(*args, **kwargs)

self._api_keys = {}

Expand All @@ -36,22 +33,27 @@ def get_api_key(self, name, default=None):
try:
return self._api_keys[name]
except LookupError:
self._api_keys[name] = value = self.get('api_keys', {}).get(name, default)
self._api_keys[name] = value = self.get("api_keys", {}).get(
name, default
)
return value

def load_config(self):
"""(re)loads the bot config from the config file"""
self._api_keys.clear()
if not os.path.exists(self.path):
if not self.path.exists():
# if there is no config, show an error and die
logger.critical("No config file found, bot shutting down!")
print("No config file found! Bot shutting down in five seconds.")
print("Copy 'config.default.json' to 'config.json' for defaults.")
print("For help, see http://git.io/cloudbotirc. Thank you for using CloudBot!")
print(
"For help, see htps://github.com/TotallyNotRobots/CloudBot. "
"Thank you for using CloudBot!"
)
time.sleep(5)
sys.exit()

with open(self.path) as f:
with self.path.open(encoding="utf-8") as f:
data = json.load(f, object_pairs_hook=OrderedDict)

self.update(data)
Expand All @@ -64,7 +66,7 @@ def load_config(self):

def save_config(self):
"""saves the contents of the config dict to the config file"""
with open(self.path, 'w') as f:
with self.path.open("w", encoding="utf-8") as f:
json.dump(self, f, indent=4)

logger.info("Config saved to file.")
6 changes: 3 additions & 3 deletions docs/installing/nix.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
[Quick Install](#quick-install)

#### Archive
Download CloudBot from [https://github.com/TotallyNotRobots/CloudBot/archive/master.zip](https://github.com/TotallyNotRobots/CloudBot/archive/master.zip) and unzip, or execute the following commands:
Download CloudBot from [https://github.com/TotallyNotRobots/CloudBot/archive/main.zip](https://github.com/TotallyNotRobots/CloudBot/archive/main.zip) and unzip, or execute the following commands:
```bash
curl -Ls https://github.com/TotallyNotRobots/CloudBot/archive/master.zip > CloudBot.zip
curl -Ls https://github.com/TotallyNotRobots/CloudBot/archive/main.zip > CloudBot.zip
unzip CloudBot.zip
cd CloudBot-master
cd CloudBot-main
```

#### Git
Expand Down
2 changes: 1 addition & 1 deletion docs/installing/win.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ If that doesn't work, follow [this guide](http://simpledeveloper.com/how-to-inst

### Downloading

Download CloudBot from [https://github.com/TotallyNotRobots/CloudBot/archive/master.zip](https://github.com/TotallyNotRobots/CloudBot/archive/master.zip).
Download CloudBot from [https://github.com/TotallyNotRobots/CloudBot/archive/main.zip](https://github.com/TotallyNotRobots/CloudBot/archive/main.zip).

Unzip the resulting file, and continue to read this document.

Expand Down
12 changes: 6 additions & 6 deletions docs/user/main_user.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,32 @@ In this guide, we will cover the setup and configuration procedures in the follo

## 1 - Getting CloudBot

Setting up CloudBot on a new server instance is simple. To begin, you need a compatible server that supports **Python 3.4**. Earlier versions of Python are not compatible due to the use of *asyncIO*.
Setting up CloudBot on a new server instance is simple. To begin, you need a compatible server that supports **Python 3.6**. Earlier versions of Python are not compatible.

We recommend using the stable releases of CloudBot that can be found [on the releases page](https://github.com/CloudBotIRC/CloudBot/releases), or from the `master` branch on GitHub.
We recommend using the stable releases of CloudBot that can be found [on the releases page](https://github.com/TotallyNotRobots/CloudBot/releases), or from the `main` branch on GitHub.

#### Using HTTP

If you only have command-line access, run the following in your terminal:

**On Linux:**
```
wget https://github.com/CloudBotIRC/CloudBot/archive/master.zip
wget https://github.com/TotallyNotRobots/CloudBot/archive/main.zip
```

**On OS X:**
```
curl -O https://github.com/CloudBotIRC/CloudBot/archive/master.zip
curl -O https://github.com/TotallyNotRobots/CloudBot/archive/main.zip
```

Followed by `unzip master.zip` on both OSs.
Followed by `unzip main.zip` on both OSs.

#### Using Git

You can also use Git to pull a new version of CloudBot, (which is useful for making upgrades easier). This can be accomplished with

```
git clone https://github.com/CloudBotIRC/CloudBot.git
git clone https://github.com/TotallyNotRobots/CloudBot.git
cd CloudBot
```

Expand Down
35 changes: 35 additions & 0 deletions tests/core_tests/config_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from unittest.mock import MagicMock

import pytest

from cloudbot.config import Config


def test_config_load_no_file(tmp_path, capsys):
bot = MagicMock()
config_file = tmp_path / "config.json"
with pytest.raises(SystemExit):
Config(bot, filename=config_file)

data = capsys.readouterr()
assert data.out == (
"No config file found! Bot shutting down in five "
"seconds.\n"
"Copy 'config.default.json' to "
"'config.json' for defaults.\n"
"For help, "
"see htps://github.com/TotallyNotRobots/CloudBot. "
"Thank you for "
"using CloudBot!\n"
)


def test_save(tmp_path):
config_file = tmp_path / "config.json"
config_file.write_text("{}")
bot = MagicMock()
cfg = Config(bot, filename=config_file)
cfg["foo"] = "bar"
cfg.save_config()

assert config_file.read_text() == '{\n "foo": "bar"\n}'
17 changes: 11 additions & 6 deletions tests/plugin_tests/test_chatbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ def load_config(self):

class MockBot:
def __init__(self, config):
self.config = MockConfig(self, config)
self.config = MockConfig(self)
self.config.update(config)


def test_make_api():
from plugins import chatbot
from plugins.chatbot import make_api
bot = MockBot({'api_keys': {'cleverbot': 'testapikey'}})

bot = MockBot({"api_keys": {"cleverbot": "testapikey"}})
make_api(bot)
assert chatbot.container.api.key == 'testapikey'
assert chatbot.container.api.key == "testapikey"


def test_chitchat():
Expand All @@ -27,11 +29,14 @@ def test_chitchat():

chatbot.container.api = None

assert chitchat('foobar') == "Please add an API key from http://www.cleverbot.com/api to enable this feature."
assert (
chitchat("foobar")
== "Please add an API key from http://www.cleverbot.com/api to enable this feature."
)

mock_api = MagicMock()
chatbot.container.api = mock_api

chitchat('foobar123')
chitchat("foobar123")

mock_api.say.assert_called_with('foobar123')
mock_api.say.assert_called_with("foobar123")
Loading

0 comments on commit a4a71b6

Please sign in to comment.