OtakuMegane / DerpyBot

An active learning chatbot using Markov chains.
MIT License
5 stars 3 forks source link

Syntax error, \discord_client\config.py #2

Closed ineptvirus closed 6 years ago

ineptvirus commented 6 years ago

Hi

Running the client I am presented with the following lines on startup:

===== RESTART: C:\Users\menja01\Desktop\bot\DerpyBot-master\derpybot.py =====
[DerpyBot] DerpyBot version 0.9.3.4
[DerpyBot] Loading markov...
[DerpyMarkov] Loading DerpyMarkov...
[DerpyMarkov] DerpyMarkov version 0.9.3.4
[DerpyMarkov] I know 1 lines containing a total of 1 words.
[DerpyMarkov] 1 of those words are unique.
[DerpyMarkov] We are currently using a state size of 1 which generated 2 contexts.
[DerpyMarkov] Normal reply rate is 2.0 and bot name reply rate is 100.0.
[DerpyBot] Loading chat client...
Traceback (most recent call last):
  File "C:\Users\menja01\Desktop\bot\DerpyBot-master\derpybot.py", line 131, in <module>
    client_load(False)
  File "C:\Users\menja01\Desktop\bot\DerpyBot-master\derpybot.py", line 88, in client_load
    chat_client = importlib.import_module('clients.discord_client.discord_client')
  File "C:\Users\menja01\AppData\Local\Programs\Python\Python36-32\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Users\menja01\Desktop\bot\DerpyBot-master\clients\discord_client\discord_client.py", line 8, in <module>
    from . import config
  File "C:\Users\menja01\Desktop\bot\DerpyBot-master\clients\discord_client\config.py", line 8
    command_alias = "#"
                ^
SyntaxError: invalid syntax
>>> 

The arrow is pointing to the s on the end of alias btw.

I thought okay lets have a look at the \discord_client\config.py file it looks like it is trying to load, I have it setup as follows with the bot info taken out:

from configparser import SafeConfigParser
import common

config = SafeConfigParser()
bot_token = "REDACTED"
discord_playing = "playing with AI"
owner_ids = [Ineptvirus#1337]
command_alias = "#"
discord_channels = [general]
discord_markov_channels = [general]
chat_to_console = None
#TODO: config.has_section, sanity checks

The error occuring on command alias, I changed the previous line to; owner_ids = ["Ineptvirus#1337"]

I think this fixes it because it passes that line but then it gets stuck on line 9 next time I run it with the following error:

===== RESTART: C:\Users\menja01\Desktop\bot\DerpyBot-master\derpybot.py =====
[DerpyBot] DerpyBot version 0.9.3.4
[DerpyBot] Loading markov...
[DerpyMarkov] Loading DerpyMarkov...
[DerpyMarkov] DerpyMarkov version 0.9.3.4
[DerpyMarkov] I know 1 lines containing a total of 1 words.
[DerpyMarkov] 1 of those words are unique.
[DerpyMarkov] We are currently using a state size of 1 which generated 2 contexts.
[DerpyMarkov] Normal reply rate is 2.0 and bot name reply rate is 100.0.
[DerpyBot] Loading chat client...
Traceback (most recent call last):
  File "C:\Users\menja01\Desktop\bot\DerpyBot-master\derpybot.py", line 131, in <module>
    client_load(False)
  File "C:\Users\menja01\Desktop\bot\DerpyBot-master\derpybot.py", line 88, in client_load
    chat_client = importlib.import_module('clients.discord_client.discord_client')
  File "C:\Users\menja01\AppData\Local\Programs\Python\Python36-32\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Users\menja01\Desktop\bot\DerpyBot-master\clients\discord_client\discord_client.py", line 8, in <module>
    from . import config
  File "C:\Users\menja01\Desktop\bot\DerpyBot-master\clients\discord_client\config.py", line 9, in <module>
    discord_channels = [general]
NameError: name 'general' is not defined
>>> 

Not sure where to go from here.

Edit: I changed owner ID to = 0 Just like in defaults. And when run again I get the second error (line 9, general is not defined)

ineptvirus commented 6 years ago

Fixed the issue by resetting owner ID and channel settings in \discord_client\config.py to the following;

from configparser import SafeConfigParser
import common

config = SafeConfigParser()
bot_token = "REDACTED"
discord_playing = "playing with AI"
owner_ids = []
command_alias = "#"
discord_channels = []
discord_markov_channels = []
chat_to_console = None
#TODO: config.has_section, sanity checks

Works fine now.

OtakuMegane commented 6 years ago

config.py isn't meant to be altered, it's just code. More complex to configure properly (as you discovered) and can get overwritten if the file is updated later so all the configuration is done through .cfg files.

Settings should go in config.cfg and be placed in the config directory. You can rename config.cfg.example and modify that or build one on your own. Any settings you don't specify will be taken from defaults.cfg when the script runs.

Edit: It's .cfg files, not .ini