Skip to content

Commit

Permalink
Merge pull request #2437 from gmt2001/patch-236
Browse files Browse the repository at this point in the history
Patch 236
  • Loading branch information
gmt2001 committed Jan 13, 2021
2 parents 487f078 + b39d077 commit c06512c
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 35 deletions.
2 changes: 1 addition & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

<property environment="env" />
<!-- Please see this for version numbers: https://semver.org/ -->
<property name="version" value="3.4.0" />
<property name="version" value="3.4.1" />
<!-- Please see this for version numbers: https://semver.org/ -->
<property name="webpanel.version" value="1.4.0" />
<property name="src" location="source" />
Expand Down
14 changes: 8 additions & 6 deletions docs/guides/content/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The following Markdown is supported for PhantomBot Guides

<!-- toc -->

<!-- tocstop -->

&nbsp;

#### Italic
Expand Down Expand Up @@ -317,9 +319,9 @@ https://www.youtube.com/watch?v=dQw4w9WgXcQ
```

**Output:**
# Heading 1
## Heading 2
### Heading 3
#### Heading 4
##### Heading 5
###### Heading 6
<!-- notoc # --> Heading 1
<!-- notoc ## --> Heading 2
<!-- notoc ### --> Heading 3
<!-- notoc #### --> Heading 4
<!-- notoc ##### --> Heading 5
<!-- notoc ###### --> Heading 6
18 changes: 16 additions & 2 deletions docs/guides/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,10 @@ <h3 class="box-title">Jump Link</h3>
md.use(window.iframify);
md.use(function(md) {
md.renderer.rules.heading_open = function(tokens, idx) {
return '<h' + tokens[idx].hLevel + ' id=' + window.markdownToc.slugify(tokens[idx + 1].content) + '>';
return '<h' + tokens[idx].hLevel + ' id=' + slugify(tokens[idx + 1].content) + '>';
};
md.renderer.rules.heading_close = function(tokens, idx) {
return ' <a style="cursor: pointer;" onclick="$(\'#copy-box\').css(\'top\', $(this).parent().offset().top + $(this).parent().outerHeight() + 5); $(\'#copy-box-input\').val(\'' + window.renderdata + '&jumpto=' + window.markdownToc.slugify(tokens[idx - 1].content) +'\'); $(\'#copy-box\').show();"><i class="fas fa-link"></i></a></h' + tokens[idx].hLevel + '>\n';
return ' <a style="cursor: pointer;" onclick="$(\'#copy-box\').css(\'top\', $(this).parent().offset().top + $(this).parent().outerHeight() + 5); $(\'#copy-box-input\').val(\'' + window.renderdata + '&jumpto=' + slugify(tokens[idx - 1].content) +'\'); $(\'#copy-box\').show();"><i class="fas fa-link"></i></a></h' + tokens[idx].hLevel + '>\n';
};
});
md.use(function(md) {
Expand Down Expand Up @@ -231,6 +231,13 @@ <h3 class="box-title">Jump Link</h3>
return ' <a href="#' + id + '" class="footnote-backref">↩</a>';
};
});

function slugify(content) {
content = content.replace(/youtube/ig, 'you-tube').replace(/vimeo/ig, 'vim-eo').replace(/vine/ig, 'vi-ne');
content = content.replace(/videopress/ig, 'video-press').replace(/wistia/ig, 'wis-tia');
let slug = window.markdownToc.slugify(content);
return encodeURIComponent(slug);
}

function loadMenuRecursive(path, tree) {
$.ajax(window.location.origin + window.location.pathname + path + 'toc.json', {
Expand Down Expand Up @@ -307,13 +314,17 @@ <h3 class="box-title">Jump Link</h3>
$.ajax(window.location.origin + window.location.pathname + path + '.md', {
'dataType': 'text',
'success': function (data) {
data = data.replace(/<!-- toc -->/, '<!-- realtoc -->').replace(/<!-- tocstop -->/, '<!-- realtocstop -->');
data = data.replace(/<!-- toc -->/ig, '<!-- faketoc -->').replace(/<!-- tocstop -->/ig, '<!-- faketocstop -->');
data = data.replace(/<!-- realtoc -->/, '<!-- toc -->').replace(/<!-- realtocstop -->/, '<!-- tocstop -->');
data = window.markdownToc.insert(data, {
filter: function(str, ele, arr) {
ele.content = ele.content.replace(/`/g, '').replace(/:\*\*]/, '**]').replace(/:\]/, ']');
return true;
},
linkify: function(token, anchor, slug, opts) {
let newhash = 'guide=' + path;
slug = slugify(token.content);
for (let x in hashmap) {
if (x !== 'jumpto' && x !== 'guide' && x.length > 0) {
if (newhash.length > 0) {
Expand All @@ -330,6 +341,9 @@ <h3 class="box-title">Jump Link</h3>
}
});
data = data.replace(/<!-- toc -->/, '').replace(/<!-- tocstop -->/, '');
data = data.replace(/<!-- faketoc -->/ig, '<!-- toc -->').replace(/<!-- faketocstop -->/ig, '<!-- tocstop -->');
data = data.replace(/<!-- notoc # -->/ig, '#').replace(/<!-- notoc ## -->/ig, '##').replace(/<!-- notoc ### -->/ig, '###');
data = data.replace(/<!-- notoc #### -->/ig, '####').replace(/<!-- notoc ##### -->/ig, '#####').replace(/<!-- notoc ###### -->/ig, '######');
window.renderdata = window.location.href.substring(0, (window.location.href + "#").indexOf('#')) + '#guide=' + path;
$('#content-pane').html(md.render(data));
$('#' + lastPage + '-menuitem').removeClass('active');
Expand Down
7 changes: 2 additions & 5 deletions javascript-source/core/keywordCoolDown.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@
* @return number
*/
function getCooldown(keyword) {
if ($.inidb.exists('coolkey', keyword.toLowerCase())) {
return parseInt($.inidb.get('coolkey', keyword.toLowerCase()));
} else if ($.inidb.exists('coolkey', keyword)) { // ignore case
if ($.inidb.exists('coolkey', keyword)) {
return parseInt($.inidb.get('coolkey', keyword));
} else {
return 0;
Expand All @@ -64,7 +62,6 @@
}

time = ((time * 1000) + $.systemTime());
keyword = keyword.toLowerCase();

cooldown.push({
keyword: keyword,
Expand All @@ -81,7 +78,7 @@
* @return number
*/
function get(keyword, username) {
var hasCooldown = $.inidb.exists('coolkey', keyword.toLowerCase()) || $.inidb.exists('coolkey', keyword), // ignore case.
var hasCooldown = $.inidb.exists('coolkey', keyword),
i;

if (!hasCooldown)
Expand Down
39 changes: 33 additions & 6 deletions javascript-source/core/updates.js
Original file line number Diff line number Diff line change
Expand Up @@ -555,11 +555,11 @@

$.inidb.RemoveFile('quotes');


for (i in temp) {
$.inidb.set('quotes', i, temp[i]);
}

$.inidb.SaveAll(true);

$.inidb.del('modules', './handlers/discordHandler.js');
Expand Down Expand Up @@ -644,7 +644,7 @@
var keys = $.inidb.GetKeyList('points', ''),
i;


for (i in keys) {
if (keys[i].match(/[A-Z]/)) {
if ($.inidb.get('points', keys[i]) == null) {
Expand Down Expand Up @@ -672,7 +672,7 @@
$.consoleLn('[permission] [remove] ' + keys[i]);
}
}

$.inidb.SaveAll(true);

$.consoleLn('PhantomBot update 2.3.6b completed!');
Expand Down Expand Up @@ -932,6 +932,33 @@
$.inidb.set('updates', 'installedv3.3.6', 'true');
}

/* version 3.4.1 updates */
if (!$.inidb.exists('updates', 'installedv3.4.1') || $.inidb.get('updates', 'installedv3.4.1') != 'true') {
$.consoleLn('Starting PhantomBot update 3.4.1 updates...');

var keys = $.inidb.GetKeyList('keywords', ''),
i,
coolkey,
json;

for (i = 0; i < keys.length; i++) {
json = JSON.parse($.inidb.get('keywords', keys[i]));

if (json.isCaseSensitive) {
coolkey = $.inidb.get('coolkey', $.jsString(json.keyword).toLowerCase());
$.inidb.del('coolkey', $.jsString(json.keyword).toLowerCase());
$.inidb.set('coolkey', json.keyword, coolkey);
} else {
json.keyword = $.jsString(json.keyword).toLowerCase();
$.inidb.del('keywords', keys[i]);
$.inidb.set('keywords', json.keyword, JSON.stringify(json));
}
}

$.consoleLn('PhantomBot update 3.4.1 completed!');
$.inidb.set('updates', 'installedv3.4.1', 'true');
}

/**
* @function getTableContents
* @param {string} tableName
Expand Down Expand Up @@ -981,11 +1008,11 @@
function restoreTableContents(tableName, contents) {
var i;


for (i in contents) {
$.inidb.set(tableName, i, contents[i]);
}

$.inidb.SaveAll(true);
}
})();
23 changes: 12 additions & 11 deletions javascript-source/handlers/keywordHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@
var str = '',
caseAdjustedMessageParts = messageParts;
if (!json.isCaseSensitive) {
json.keyword = json.keyword.toLowerCase();
caseAdjustedMessageParts = messagePartsLower;
}
for (var idx = 0; idx < caseAdjustedMessageParts.length; idx++) {
Expand Down Expand Up @@ -139,10 +138,10 @@
} else if (args[i].equalsIgnoreCase('--case-sensitive')) {
isCaseSensitive = true;
} else {
keyword = args[i] + '';
keyword = $.jsString(args[i]);
}
} else {
response = args.splice(i).join(' ');
response = $.jsString(args.splice(i).join(' '));
break;
}
}
Expand All @@ -152,6 +151,10 @@
return;
}

if (!isCaseSensitive) {
keyword = keyword.toLowerCase();
}

var json = JSON.stringify({
keyword: keyword,
response: response,
Expand All @@ -171,13 +174,11 @@
if (subAction === undefined) {
$.say($.whisperPrefix(sender) + $.lang.get('keywordhandler.remove.usage'));
return;
} else if (!$.inidb.exists('keywords', subAction.toLowerCase())) {
} else if (!$.inidb.exists('keywords', subAction)) {
$.say($.whisperPrefix(sender) + $.lang.get('keywordhandler.keyword.404'));
return;
}

subAction = args[1].toLowerCase();

$.inidb.del('keywords', subAction);
$.say($.whisperPrefix(sender) + $.lang.get('keywordhandler.keyword.removed', subAction));
loadKeywords();
Expand All @@ -190,21 +191,21 @@
if (subAction === undefined || isNaN(parseInt(args[2]))) {
$.say($.whisperPrefix(sender) + $.lang.get('keywordhandler.cooldown.usage'));
return;
} else if (!$.inidb.exists('keywords', subAction.toLowerCase())) {
} else if (!$.inidb.exists('keywords', subAction)) {
$.say($.whisperPrefix(sender) + $.lang.get('keywordhandler.keyword.404'));
return;
}

if (args[2] === -1) {
$.inidb.del('coolkey', subAction.toLowerCase());
$.inidb.del('coolkey', subAction);
$.say($.whisperPrefix(sender) + $.lang.get('keywordhandler.cooldown.removed', subAction));
$.coolDownKeywords.clear(subAction.toLowerCase());
$.coolDownKeywords.clear(subAction);
return;
}

$.inidb.set('coolkey', subAction.toLowerCase(), parseInt(args[2]));
$.inidb.set('coolkey', subAction, parseInt(args[2]));
$.say($.whisperPrefix(sender) + $.lang.get('keywordhandler.cooldown.set', subAction, args[2]));
$.coolDownKeywords.clear(subAction.toLowerCase());
$.coolDownKeywords.clear(subAction);
}
}
});
Expand Down
8 changes: 4 additions & 4 deletions source/com/gmt2001/Console/warn.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static void print(Object o) {
stackInfo = "[" + methodName + "()@" + fileName + ":" + lineNumber + "] ";

Logger.instance().log(Logger.LogType.Warning, "[" + logTimestamp.log() + "] " + stackInfo + o.toString());
System.out.print("[" + logTimestamp.log() + "] [INFO] " + o);
System.out.print("[" + logTimestamp.log() + "] [WARN] " + o);
}

public static void println() {
Expand All @@ -44,7 +44,7 @@ public static void println() {

public static void printlnRhino(Object o) {
// Do not write to a log file as the JS Rhino files already do this. //
System.out.println("[" + logTimestamp.log() + "] [INFO] " + o);
System.out.println("[" + logTimestamp.log() + "] [WARN] " + o);
}

public static void println(Object o) {
Expand All @@ -56,7 +56,7 @@ public static void println(Object o) {

Logger.instance().log(Logger.LogType.Warning, "[" + logTimestamp.log() + "] " + stackInfo + o.toString());
Logger.instance().log(Logger.LogType.Warning, "");
System.out.println("[" + logTimestamp.log() + "] [INFO] " + stackInfo + o.toString());
System.out.println("[" + logTimestamp.log() + "] [WARN] " + stackInfo + o.toString());
}

public static void println(Object o, Boolean logOnly) {
Expand All @@ -69,7 +69,7 @@ public static void println(Object o, Boolean logOnly) {
Logger.instance().log(Logger.LogType.Warning, "[" + logTimestamp.log() + "] " + stackInfo + o.toString());
Logger.instance().log(Logger.LogType.Warning, "");
if (!logOnly) {
System.out.println("[" + logTimestamp.log() + "] [INFO] " + stackInfo + o.toString());
System.out.println("[" + logTimestamp.log() + "] [WARN] " + stackInfo + o.toString());
}
}

Expand Down
2 changes: 2 additions & 0 deletions source/tv/phantombot/PhantomBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,8 @@ public PhantomBot(CaselessProperties pbProperties) {
/* Validate the chat OAUTH token. */
TwitchValidate.instance().validateChat(this.oauth, "CHAT (oauth)");

TwitchValidate.instance().checkOAuthInconsistencies(this.botName);

/* Set the TwitchAlerts OAuth key and limiter. */
if (!twitchAlertsKey.isEmpty()) {
TwitchAlertsAPIv1.instance().SetAccessToken(twitchAlertsKey);
Expand Down
16 changes: 16 additions & 0 deletions source/tv/phantombot/twitch/api/TwitchValidate.java
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,22 @@ public String getCustomUserID() {
return this.useridT;
}

public void checkOAuthInconsistencies(String botName) {
if (this.hasAPIScope("chat:edit") && !this.hasChatScope("chat:edit")) {
com.gmt2001.Console.warn.println("CHAT (oauth) does not have chat:edit but API (apioauth) does. OAuth tokens may be reversed");
} else if (!this.hasChatScope("chat:edit")) {
com.gmt2001.Console.warn.println("CHAT (oauth) does not have chat:edit. Bot may be unable to respond");
} else if (!this.hasChatScope("channel:moderate")) {
com.gmt2001.Console.warn.println("CHAT (oauth) does not have channel:moderate. Bot may be unable to purge/timeout/ban");
}

if (this.getAPILogin().equalsIgnoreCase(botName) && !this.getChatLogin().equalsIgnoreCase(botName)){
com.gmt2001.Console.warn.print("CHAT (oauth) is not logged in as " + botName + " but API (apioauth) is. OAuth tokens may be reversed");
} else if (!this.getChatLogin().equalsIgnoreCase(botName)){
com.gmt2001.Console.warn.print("CHAT (oauth) is not logged in as " + botName + ". OAuth token may be under the wrong login");
}
}

/**
* Runnable to push the validation checks to the background so as not to block the operation of the bot at start up.
*/
Expand Down

0 comments on commit c06512c

Please sign in to comment.